题目:https://vj.69fa.cn/1fc993e7e0e1e6fa7ce4640b8d46ef8d?v=1552762626

这个题目,之前有一点思路,但是呢,后来又不知道怎么去执行,然后就没有了耐心就去网上找了题解,这个去遍历每一个数,如果和他挨在一起就把它标记为相同的数d。

然后之后判断如果又有标记相同的齿轮挨在一起则可以说明是三个齿轮紧紧扣在一起,就返回假,这个标记d也有特殊含义,这个标记按照正负去标记,这样最后一个和第一个符号进行判断就可以

知道是不是顺时针,刚刚就在想可不可以用bfs呢?然后就去试了一下,发现可以用bfs写。。。。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <queue>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1100;
int dir[maxn] , n;
struct node
{
int x, y, r;
//node(int x = 0, int y = 0) :x(x), y(y){}
}exa[maxn];
struct heapnode
{
int id, d;
heapnode(int id=0,int d=0):id(id),d(d){}
}; int gcd(int a,int b)
{
return b == 0 ? a : gcd(b, a%b);
} bool fill(int i,int d)
{
dir[i] = d;
for(int j=1;j<=n;j++)
{
int dx = (exa[i].x - exa[j].x)*(exa[i].x - exa[j].x);
int dy = (exa[i].y - exa[j].y)*(exa[i].y - exa[j].y);
int R = (exa[i].r + exa[j].r)*(exa[i].r + exa[j].r);
if(i!=j&&dx+dy==R)
{
if (dir[i] == dir[j]) return false;
if (dir[j]) continue;
if (!fill(j, -d)) return false;
}
}
return true;
} bool bfs()
{
queue<heapnode>que;
que.push(heapnode(1,1));
dir[1] = 1;
while(!que.empty())
{
heapnode a = que.front(); que.pop();
int u = a.id;
int d = a.d;
for(int i=1;i<=n;i++)
{
int dx = (exa[u].x - exa[i].x)*(exa[u].x - exa[i].x);
int dy = (exa[u].y - exa[i].y)*(exa[u].y - exa[i].y);
int R = (exa[u].r + exa[i].r)*(exa[u].r + exa[i].r);
if(i!=u&&dx+dy==R)
{
if (dir[u] == dir[i]) return false;
if (dir[i]) continue;
dir[i] = -d;
que.push(heapnode(i, -d));
}
}
}
return true;
} int main()
{ cin >> n;
memset(dir, 0, sizeof(dir));
for(int i=1;i<=n;i++)
{
scanf("%d %d %d", &exa[i].x, &exa[i].y, &exa[i].r);
}
if (!bfs()) printf("The input gear cannot move.\n");
else if (!dir[n]) printf("The input gear is not connected to the output gear.\n");
else
{
int g = gcd(exa[1].r, exa[n].r);
dir[1] = dir[1] * dir[n];
printf("%d:%d\n", dir[1] * exa[1].r/g, exa[n].r/g);
}
return 0;
}

  

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1100;
int dir[maxn] , n;
struct node
{
int x, y, r;
}exa[maxn]; int gcd(int a,int b)
{
return b == 0 ? a : gcd(b, a%b);
} bool fill(int i,int d)
{
dir[i] = d;
for(int j=1;j<=n;j++)
{
int dx = (exa[i].x - exa[j].x)*(exa[i].x - exa[j].x);
int dy = (exa[i].y - exa[j].y)*(exa[i].y - exa[j].y);
int R = (exa[i].r + exa[j].r)*(exa[i].r + exa[j].r);
if(i!=j&&dx+dy==R)
{
if (dir[i] == dir[j]) return false;
if (dir[j]) continue;
if (!fill(j, -d)) return false;
}
}
return true;
} int main()
{ cin >> n;
memset(dir, 0, sizeof(dir));
for(int i=1;i<=n;i++)
{
scanf("%d %d %d", &exa[i].x, &exa[i].y, &exa[i].r);
}
if (!fill(1, 1)) printf("The input gear cannot move.\n");
else if (!dir[n]) printf("The input gear is not connected to the output gear.\n");
else
{
int g = gcd(exa[1].r, exa[n].r);
dir[1] = dir[1] * dir[n];
printf("%d:%d\n", dir[1] * exa[1].r/g, exa[n].r/g);
}
return 0;
}

  

gear gym 思维题的更多相关文章

  1. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

  2. 思维题 Gym 100553A Alter Board

    题目传送门 /* 题意:一个n×m的矩形,相邻的颜色不同,黑或白.问最少的翻转次数,每次翻转可指定任意一个子矩形 思维题:最少要把偶数行和列翻转,也就是n/2+m/2次 */ #include < ...

  3. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  4. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  5. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  6. 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)

    思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...

  7. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  9. HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)

    HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...

随机推荐

  1. 行为型---中介者模式(Mediator Pattern)

    中介者模式的定义 中介者模式,定义了一个中介对象来封装一系列对象之间的交互关系.中介者使各个对象之间不需要显式地相互引用,从而使耦合性降低,而且可以独立地改变它们之间的交互行为.   中介者模式的结构 ...

  2. vue elementUI enter 回车 (转载)

    表单提交时需要处理输入框的回车事件 一.vue原生 原生input标签可以用@keyup.enter="onSubmit" 如:<input v-on:keyup.enter ...

  3. ASP.NET MVC3 在_ViewStart设置Layout使用RenderAction的注意事項

    来源:https://dotblogs.com.tw/lastsecret/archive/2012/03/26/71052.aspx ASP.NET MVC3 在_ViewStart設定Layout ...

  4. 1.Linux电源管理-休眠与唤醒

    1.休眠方式 在内核中,休眠方式有很多种,可以通过下面命令查看 # cat /sys/power/state //来得到内核支持哪几种休眠方式. 常用的休眠方式有freeze,standby, mem ...

  5. wp rest api 授权方法步骤(使用JWT Authentication插件)

    环境:wordpress 4.7 以上,WP自带的 rest api v2 目标:使用javascript与wp rest api交互,其中编辑.新增.删除等需要Oauth认证授权 方法: 步骤一:  ...

  6. Java并发编程学习:volatile关键字解析

    转载:https://www.cnblogs.com/dolphin0520/p/3920373.html 写的非常棒,好东西要分享一下 Java并发编程:volatile关键字解析 volatile ...

  7. 前端入门8-JavaScript语法之数据类型和变量

    声明 本系列文章内容全部梳理自以下几个来源: <JavaScript权威指南> MDN web docs Github:smyhvae/web Github:goddyZhao/Trans ...

  8. express入门

    (1)express的安装 $ npm install express 或者 $ npm install -g express 或者 $ npm install express -gd 备注: -g ...

  9. ATOM中MARKDOWN的使用小结

    1.ctrl+shift+p ; 输入ssvvp ; 回车 2.输入markdown-preview进行安装 3.打开任意.md 文件 ; 按 ctrl-shift-m 进行预览

  10. 微信小程序使用wxParse,解决图片显示路径问题

    我们经常用到发布文章,用的是UEditor百度富文本编辑器,方便排版,存储的也是html代码,这样小程序解析出来的也是排版的样式,但是使用wxParse解析html的时候,因为存储的是图片的相对路径, ...