题目: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. springMVC_06数据的处理

    一.提交数据的处理 *springmvc是单例的 1. 提交的域名称和处理方法的参数一致即可 提交的数据 处理方法 2.如果域名城和参数名不一致,在方法内加上域名称eg.(RequestParam(“ ...

  2. Itween 动画插件中 的画线

    1.首先在你的层次视图中创建所需的节点 ,节点的位置顺序排列 2.导入Itween 插件 1.可以直接从项目外部拖拽到本项目中 2.通过AssetStore 中导入 3.在你的父节点上创建脚本 ,对象 ...

  3. javascript模块化编程-立即执行函数(IIFE)

    IIFE 全拼Imdiately Invoked Function Expression,立即执行的函数表达式. 语法 var module1 = (function(){ var _count = ...

  4. 定时任务Crontab

    0.基本概念 & 实现原理  定时任务基本概念: 调度器:负责管理Quartz应用运行时环境,用于调度定时任务. 定时任务:按照某种时间规则,被调度的任务. a.从有无状态来说,有以下两种: ...

  5. C#基础(204)--对象初始化器,基本数据类型与引用数据类型特点总结,ref,out关键字的使用

    对象初始化器: 对象在创建过程中也可以使用对象初始化器完成“属性的初始化” Student stu =new Student(){ StudentId=, StudentName="张三&q ...

  6. 腾讯.NET&PHP面试题

    在整个面试过程中,作为面试者的你,角色就是小怪兽,面试官的角色则是奥特曼,更不幸的是,作为小怪兽的你是孤身一人,而奥特曼却往往有好几个助攻,你总是被虐得不要不要的~ 作为复读一年才考上专科的我,遗憾的 ...

  7. Openlayer3中应用的技术

    ol3-ext有很多很丰富的效果,可以不用重复造轮子,ol3-ext示例大全:http://viglino.github.io/ol3-ext/ 在本次项目中使用到了ol3-ext的两个功能:图层管理 ...

  8. Apache httpd.conf配置文件主要内容解释

    1 ServerRoot 配置 ["ServerRoot" 主要用于指定Apache的安装路径,此选项参数值在安装Apache时系统会自动把Apache的路径写入.Windows安 ...

  9. 关于一体机外卖单不打印外卖单号FAQ(适用正餐6.0.09,轻餐4.0.6.1,轻餐4.0.6.2)

    适用情景:升级版本后打印机打印出的外卖小票不出现外卖单号. 解决方案:设置-功能设置-小票设置-小票自定义-前台小票-外卖订单-------选择编辑,选中右侧中外卖单号或者外卖订单编号,点击保存即可. ...

  10. sql prompt 缩写 快捷键

    快捷键代码 1. df DELETE FROM 2. ssf SELECT * FROM  3. be BEGIN  END 4. ij INNER JOIN  5. ap ALTER PROCEDU ...