Yet another end of the world
时间限制: | 5000 Ms |
内存限制: | 65535 Kb |
问题描述
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.
输入说明
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*10^9).
输出说明
输入样例
2 7 2 3 7 5 6 2 7 2 2 9 2 2
输出样例
Can Take off Cannot Take off
来源
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 using namespace std; 5 6 int gcd(int a,int b) { 7 return b==0 ? a:gcd(b,a%b); 8 } 9 const int MAXN=1010; 10 int x[MAXN],y[MAXN],z[MAXN]; 11 12 bool check2(int d,int l,int r) { //判断d的倍数能不能在[l,r]区间上 13 if(l%d==0 || r%d==0)return true; 14 if(r-l+1>=d)return true; 15 int t1=l/d,t2=r/d; 16 if(t1!=t2)return true; 17 else return false; 18 } 19 20 bool check(int i,int j) { 21 if(y[i]>z[j]||y[j]>z[i]) { 22 if(z[i]<y[j]) swap(i,j); 23 int d=gcd(x[i],x[j]); 24 if(check2(d,y[i]-z[j],z[i]-y[j]))return true; 25 else return false; 26 } 27 return true; 28 } 29 //求 y[i]-z[j]=gcd(x[i],y[j]) 30 int main() { 31 int n; 32 while(scanf("%d",&n)==1) { 33 for(int i=0; i<n; i++) 34 scanf("%d%d%d",&x[i],&y[i],&z[i]); 35 bool flag=true; 36 for(int i=0; i<n-1; i++) { 37 for(int j=i+1; j<n; j++) 38 if(check(i,j)) { 39 flag=false; 40 break; 41 } 42 if(!flag) break; 43 } 44 45 if(flag) puts("Can Take off"); 46 else puts("Cannot Take off"); 47 } 48 return 0; 49 }