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 ...
随机推荐
- log4j-1.2.6升级到log4j-2.9.0
0.工程是普通java web工程,不是maven工程.需要升级log4j 步骤发下: 1. 在build path中 移除项目对log4j-1.2.6.jar的引用,并物理删除log4j-1.2.6 ...
- 详解MySQL基准测试和sysbench工具(转)
前言 作为一名后台开发,对数据库进行基准测试,以掌握数据库的性能情况是非常必要的.本文介绍了MySQL基准测试的基本概念,以及使用sysbench对MySQL进行基准测试的详细方法. 文章有疏漏之处, ...
- 解决mysql服务无法启动的问题
今天,mysql突然无法启动了. 解决办法记录一下: 1.删除data文件 我的:C:\Program Files\MySQL\MySQL Server 5.7\data 注意:这个文件可能在你一直试 ...
- JS基础(三)构造函数
JS中的构造函数 <script language="JavaScript"> window.onload = function(){ function Bottle( ...
- Linq 操作DataTable
class ClientStruct { public string ID = "ID"; public string Name = "Name"; publi ...
- PS换脸操作
1,使用套索工具抠出人的五官. 2,Ctrl+C复制黏贴到另一张头像中,调节透明度50%,与需要换脸的头像的眼睛,嘴巴,鼻子重合,透明度回归100%. 3,为了不该变原图,需要新建一张原图. 4,在抠 ...
- MySQL5.7: datetime
-- 当前日期时间 select now(); select now(3);-- 保留3位毫秒数 SELECT NOW(6); -- 保留6位毫秒数 -- 当前日期和时间 至秒 select curr ...
- HTML之元素分类(HTML基础知识)
HTML之元素分类 一.按照块级元素还是行内元素分类 块级元素(block-level)和行内元素(inline-level,也叫作“内联”元素). a.块级元素(独占一行) 块级元素:其最明显的特征 ...
- Python __exit__,__enter__函数with语句的组合应用
__exit__,__enter__函数with语句的组合应用 by:授客 QQ:1033553122 简介 设计对象类时,我们可以为对象类新增两个方法,一个是__enter(self)__,一个 ...
- Android 底部导航栏实现一 Fragment-replace
[效果](这里下载的软件收费的试用有水印) [推荐]这里推荐一个图标网http://iconfont.cn/.以上图标来自此图标网 [项目结构] [步骤] ①创建布局文件,写底部导航栏 <?xm ...