hdu Yet another end of the world(扩展欧几里得定理推论)
来源:互联网 发布:it程序员面试自我介绍 编辑:程序博客网 时间:2024/06/02 16:13
Yet another end of the world
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 266 Accepted Submission(s): 149
Problem Description
In the year 3013, it has been 1000 years since the previous predicted rapture. However, the Maya will not play a joke any more and the Rapture finally comes in. Fortunately people have already found out habitable planets, and made enough airships to convey all the human beings in the world. A large amount of airships are flying away the earth. People all bear to watch as this planet on which they have lived for millions of years. Nonetheless, scientists are worrying about anther problem…
As we know that long distance space travels are realized through the wormholes, which are given birth by the distortion of the energy fields in space. Airships will be driven into the wormholes to reach the other side of the universe by the suction devices placed in advance. Each wormhole has its configured attract parameters, X, Y or Z. When the value of ID%X is in [Y,Z], this spaceship will be sucked into the wormhole by the huge attraction. However, the spaceship would be tear into piece if its ID meets the attract parameters of two wormholes or more at the same time.
All the parameters are carefully adjusted initially, but some conservative, who treat the Rapture as a grain of truth and who are reluctant to abandon the treasure, combine with some evil scientists and disrupt the parameters. As a consequence, before the spaceships fly into gravity range, we should know whether the great tragedy would happen or not. Now the mission is on you.
As we know that long distance space travels are realized through the wormholes, which are given birth by the distortion of the energy fields in space. Airships will be driven into the wormholes to reach the other side of the universe by the suction devices placed in advance. Each wormhole has its configured attract parameters, X, Y or Z. When the value of ID%X is in [Y,Z], this spaceship will be sucked into the wormhole by the huge attraction. However, the spaceship would be tear into piece if its ID meets the attract parameters of two wormholes or more at the same time.
All the parameters are carefully adjusted initially, but some conservative, who treat the Rapture as a grain of truth and who are reluctant to abandon the treasure, combine with some evil scientists and disrupt the parameters. As a consequence, before the spaceships fly into gravity range, we should know whether the great tragedy would happen or not. Now the mission is on you.
Input
Multiple test cases, ends with EOF.
In each case, the first line contains an integer N(N<=1000), which means the number of the wormholes.
Then comes N lines, each line contains three integers X,Y,Z(0<=Y<=Z<X<2*109).
In each case, the first line contains an integer N(N<=1000), which means the number of the wormholes.
Then comes N lines, each line contains three integers X,Y,Z(0<=Y<=Z<X<2*109).
Output
If there exists danger, output “Cannot Take off”, else output “Can Take off”.
Sample Input
27 2 37 5 627 2 29 2 2
Sample Output
Can Take offCannot Take off
Source
2013 ACM-ICPC南京赛区全国邀请赛——题目重现
题目大意:给定1000个xi,yi,zi,问是否存在一组i,j使得t%xi=[yi,zi],t%xj=[yj,zj].比赛的时候应该自己多在纸上画一下的,其实这类题目自己开始就做过两个,而且比这个复杂一些,那个需要求解,但是这个无需求解。
解题思路:比赛一直在想着怎么过掉C题。。。t=a1*x1+b1,t=a2*x2+b2,可以转换成a1*x1+a2*x2=b2-b1,这个同余方程有解的前提是(b2-b1)%gcd(x1,x2)==0,当时还看了这方面的相关证明以及如何用扩展欧几里得求解。根据这个结论就很容易求解了,看yi,zi,yj,zj中间是否有解使得%gcd(xi,xj)==0。
题目地址:Yet another end of the world
AC代码:
#include<iostream>#include<cstdio>using namespace std;int p[1002][3]; //分别代表x,y,zint gcd(int m,int n){ int tmp; while(n) { tmp=m%n; m=n; n=tmp; } return m;}int check(int a,int b){ int d=gcd(p[a][0],p[b][0]); if(p[a][1]>p[b][1]) swap(a,b); int y1,z1,y2,z2; y1=p[a][1],z1=p[a][2],y2=p[b][1],z2=p[b][2]; if(y2<=z1) return 1; //说明两个区间有交叉,可以为0 int s1,s2; //s1-s2即为模可以取值的空间 s1=y2-z1,s2=z2-y1; if(s1%d==0) return 1; int tmp=s1/d; tmp=d*(tmp+1); if(tmp<=s2) return 1; return 0;}int main(){ int n,i,j; while(cin>>n) { for(i=0;i<n;i++) for(j=0;j<3;j++) scanf("%d",&p[i][j]); int flag=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) if(check(i,j)) { flag=1; break; } if(flag) break; } if(flag) puts("Cannot Take off"); else puts("Can Take off"); } return 0;}/*27 2 37 5 6*///781MS
- hdu Yet another end of the world(扩展欧几里得定理推论)
- [欧几里得] hdu 4596 Yet another end of the world
- HDU 4596 Yet another end of the world (拓展欧几里得)
- HDU 4596 - Yet another end of the world(扩展欧几里得)
- HDU4596 Yet another end of the world 扩展欧几里德性质
- HDU 4596 Yet another end of the world (扩展欧几里德)
- hdu 4596 Yet another end of the world(数论)
- HDU 4596 Yet another end of the world
- HDU OJ 4596 Yet another end of the world
- HDU 4569——Yet another end of the world
- Hdu 4596 Yet another end of the world(数论)
- HDU 4596Yet another end of the world(GCD)
- HDU-4596 Yet another end of the world (数论)
- HDU4596Yet another end of the world(扩展欧几里得)
- Yet another end of the world
- HDU4596 Yet another end of the world(数学公式推演+数论定理--2013南京邀请赛)
- (数论)HDU 4596 Yet another end of the world题解
- hdu 4596 Yet another end of the world (一阶不定方程可解性 )
- Java通过年月,计算月份天数。
- struts2 18拦截器详解(一) --- 准备知识
- Entity Framework 5.0系列之Code First数据库迁移
- MySQL中REPLACE INTO语句的用法
- .net版ueditor在Repeater中动态生成
- hdu Yet another end of the world(扩展欧几里得定理推论)
- How To Loop A Map In Java
- 标准库I/O vs linux api I/O全面比较一
- JetBrains PhpStorm 7 / WebStorm 7注册码+注册机
- 一个简单的线程中断的例子
- Lucene中一些英文分析器 Analyzer
- poj 快速幂+并查集
- px、dp和sp,这些单位有什么区别?
- 多线程安全无锁消息队列