题目: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. [C#] C# 知识回顾 - Lambda

    C# 知识回顾 - Lambda 序 它是第十一个希腊字母,一个拥有失意.无奈.孤独.低调等含义的流行符号,也指示一款称为“半条命”的游戏. 不过,这次我所讲的是 C# 中的 Lambda. 目录 L ...

  2. SQL 注入漏洞

    首先要知道sql注入形成的原因:用户输入的数据被sql解释器执行 sql注入又分:数字型,字符型,cookie 注入,post注入,延时注入,搜索注入,base64注入 如何甄别一个模块是否有sql注 ...

  3. 【转载】.NET开源快速开发框架Colder(NET452+AdminLTE版)

    .NET开源快速开发框架Colder(NET452+AdminLTE版) 简介 本框架旨在为.NET开发人员提供一个Web后台快速开发框架,采用本框架,能够极大的提高项目开发效率. 本版本框架采后端采 ...

  4. No.3 数组中重复的数字 (P39)

    题目1:找出数组中重复的数字 [题目描述] 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个 ...

  5. SVG的学习(34—36)

    使用js来动态绘制svg图片,首先就是要创建svg 节点. 使用createElementNS(),语法: document.createElementNS(namespaceURI, qualifi ...

  6. iPhone X手机投屏电脑无线连接教程

    iPhone X手机是一款非常有气场的手机,独特的设计,展现手机的独特魅力,手机外观让人一眼就爱上,手感也是超级的舒适,真的是堪称完美,但是iPhone X手机投屏电脑怎么无线连接呢? 使用工具: 电 ...

  7. RabbitMQ 在 web 页面 创建 exchange, queue, routing key

    这里只是为了展示, 在实际开发中一般在消费端通过 注解来自动创建 消费端: https://www.cnblogs.com/huanggy/p/9695934.html 1, 创建 Exchange ...

  8. C# SharpMap的简单使用

    本文是利用ShapMap实现GIS的简单应用的小例子,以供学习分享使用.关于SharpMap的说明,网上大多是以ShapeFile为例进行简单的说明,就连官网上的例子也不多.本文是自己参考了源代码进行 ...

  9. C# 实现连连看功能

    本文是利用C#实现连连看的小例子,以供学习分享使用.如有不足之处,还望指正. 思路: 初始化布局(横竖十行十列,共100个单元格,每一个格一个按钮,背景图为水果图片,随机生成) . 初始化对应棋盘(用 ...

  10. 学习用Node.js和Elasticsearch构建搜索引擎(5):mac本机部署canal

    1.背景介绍 最近做的一个项目需要快速检索数据,经过商讨后采用了ElasticSearch作为快速检索数据引擎,但是数据如何同步到ES中是个问题,我们最开始计划了定时任务.mysql trigger等 ...