gear gym 思维题
题目: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 思维题的更多相关文章
- 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 ...
- 思维题 Gym 100553A Alter Board
题目传送门 /* 题意:一个n×m的矩形,相邻的颜色不同,黑或白.问最少的翻转次数,每次翻转可指定任意一个子矩形 思维题:最少要把偶数行和列翻转,也就是n/2+m/2次 */ #include < ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- 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 ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- 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 ...
随机推荐
- Linux服务器评测脚本 中文IO脚本简单易懂
中文版: wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZBe ...
- 模块热替换 HMR
devserver:{hot:true},既及时更新代码,样式(需配合loader)变化,自动重编译,只适用于开发环境. 入口文件中,添加监视: + if (module.hot) {+ module ...
- 【Java每日一题】20170221
20170220问题解析请点击今日问题下方的“[Java每日一题]20170221”查看(问题解析在公众号首发,公众号ID:weknow619) package Feb2017; public cla ...
- Java学习笔记之——Manth类和String类
(1) Math:常用的数学运算,都是静态方法 方法摘要 static double abs(double a) 返回 double 值的绝对值. static float abs(float a) ...
- Docker多步构建更小的Java镜像
译者按: 最新版Docker将支持多步构建(Multi-stage build),这样使用单个Dockerfile就可以定义多个中间镜像用于构建,测试以及发布等多个步骤,并且有效减小最终镜像的大小. ...
- 10个常见的JavaScript BUG
译者按: 安全起见,在开发中我基本不用==. 原文: 10 COMMON JAVASCRIPT BUGS AND HOW TO AVOID THEM 译者: Fundebug 为了保证可读性,本文采用 ...
- H5_canvas与svg
Canvas 什么是canvas: HTML5 的 canvas 元素是使用 JavaScript 在网页上绘制图像,canvas 元素本身是没有绘图能力的,所有的绘制工作必须在 JavaScript ...
- 通过css改变svg img的颜色
需求如下图,hover的时候改变图标颜色,图标为引入的svg img 一般的解决办法有:1.字体图标改变css的color属性:2.js在hover事件中切换图片:3.老一点的方案是hover切换背景 ...
- jQuery插件开发进阶
jQuery插件开发模式 软件开发过程中是需要一定的设计模式来指导开发的,有了模式,我们就能更好地组织我们的代码,并且从这些前人总结出来的模式中学到很多好的实践. 根据<jQuery高级编程&g ...
- 让bind函数支持IE8浏览器的方法
bind函数在IE8下是不支持的,只需要在你的js文件中加入如下代码就可以支持IE8 //让bind函数支持IE8 if (!Function.prototype.bind) { Function.p ...