Hdu 4596 Yet another end of the world(数论)

来源:互联网 发布:手机的视频剪辑软件 编辑:程序博客网 时间:2024/05/16 14:51

题目链接

Yet another end of the world

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 637    Accepted Submission(s): 304


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.
 

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).
 

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 满足(x,y,z)为,y<=id%x<=z。判断是否存在一个id同时满足两组(x,y,z)。

题解:设两组数为(x1,y1,z1),(x2,y2,z2)。

设 id%x1=a

     id%x2=b;

则:

id=k1*x1+a

id=k2*x2+b

则:

k1*x1-k2*x2=b-a

显然,若(b-a)为gcd(x1,-x2)的整数倍,那么k1和k2有整数解。

代码如下:

#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#define nn 1100using namespace std;int n;int x[nn],y[nn],z[nn];int gcd(int a,int b){    if(b==0)        return a;    return gcd(b,a%b);}bool check(int i,int j){    int d=gcd(x[i],-x[j]);    if((y[j]-z[i])%d==0)        return true;    if((y[j]-z[i])/d!=(z[j]-y[i])/d)        return true;    return false;}int main(){    int i,j;    while(scanf("%d",&n)!=EOF)    {        for(i=1;i<=n;i++)        {            scanf("%d%d%d",&x[i],&y[i],&z[i]);        }        for(i=1;i<=n;i++)        {            for(j=i+1;j<=n;j++)            {                if(check(i,j))                    break;            }            if(j<=n)                break;        }        if(i<=n)            puts("Cannot Take off");        else            puts("Can Take off");    }    return 0;}


0 0
原创粉丝点击