hdu 4596 Yet another end of the world (一阶不定方程可解性 )
来源:互联网 发布:软件代理销售合同 编辑:程序博客网 时间:2024/04/29 19:59
Yet another end of the world
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 265 Accepted Submission(s): 148
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南京赛区全国邀请赛——题目重现
题意:
给出n组x,y,z。判断是否存在一个id使得id%x1∈(y1,z1),id%x2∈(y2,z2)。
思路:
设 id/x1=a , id/x2=b ,则
id-a*x1=u; (1)
id-b*x2=v; (2)
(1)-(2)得 一阶不定方程: bx2-ax1=u-v .
方程可解性为是否存在 (u-v) 是gcd(x1,x2)的整数倍。
那么问题就解决了。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <map>#include <stack>#include <vector>#include <set>#include <queue>#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1005#define MAXN 100005#define mod 100000007#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;int n,m,ans;int x[maxn],y[maxn],z[maxn];int gcd(int u,int v){ if(v==0) return u; return gcd(v,u%v);}bool isok(int t,int le,int ri){ int i,j; if(le%t==0||ri%t==0) return true ; if(le<0&&ri>=0) return true ; if(ri/t-le/t>0) return true ; return false ;}bool solve(){ int i,j,t,ma,mi; for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { t=gcd(x[i],x[j]); if(isok(t,y[i]-z[j],z[i]-y[j])) return true ; } } return false ;}int main(){ int i,j; while(~scanf("%d",&n)) { for(i=1;i<=n;i++) { scanf("%d%d%d",&x[i],&y[i],&z[i]); } if(solve()) printf("Cannot Take off\n"); else printf("Can Take off\n"); } return 0;}
- hdu 4596 Yet another end of the world (一阶不定方程可解性 )
- hdu 4596 Yet another end of the world (一阶不定方程可解性 )
- HDU 4596 Yet another end of the world(一阶不定方程是否可解,gcd)
- Hdu 4596 Yet another end of the world(数论)
- HDU 4596Yet another end of the world(GCD)
- 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 4596 Yet another end of the world
- HDU OJ 4596 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 4596 Yet another end of the world (扩展欧几里德)
- HDU 4596 - Yet another end of the world(扩展欧几里得)
- HDU 4569——Yet another end of the world
- Yet another end of the world
- HDOJ 4596 Yet another end of the world【数学】
- hdu 2509 - Be the Winner(简单博弈)
- 面向对象编程的六个基本原则
- CSS 子元素选择器
- CKFinder 2.0.2 去除 This is the demo version of CKFinder. Click here to visit our web site
- 通向架构师的道路(第二十四天)之Oracle性能调优-朝拜先知之旅
- hdu 4596 Yet another end of the world (一阶不定方程可解性 )
- sql 2005 清除日志 四舍五入
- 通向架构师的道路(第二十五天)SSH的单元测试与dbunit的整合
- Linux文件系统(一)-群居和一
- 字符的长度选择
- hdu 1272 小希的迷宫
- win7+64位+Oracle+11g+64位下使用PLSQL+Developer+无法导入.dmp的解决办法
- C函数getopt使用
- Entity Framework 5.0系列之EF概览