HDU OJ 4596 Yet another end of the world

题目:

Yet another end of the world

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


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*10 9).
 

Output
If there exists danger, output “Cannot Take off”, else output “Can Take off”.
 

Sample Input
  
  
2 7 2 3 7 5 6 2 7 2 2 9 2 2
 

Sample Output
  
  
Can Take off Cannot Take off
 

Source


代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;
long long gcd(long long a,long long b)
{
    return  (b==0)?a:gcd(b,a%b);
}
int main()
{
    long long  i,n,j,cnt,m[1005],a[1005][2],g,ma,mi,ys[2];
    bool flag;
       while(~scanf("%I64d",&n))
        {
        for(i=0;i<n;i++)
            {
                scanf("%I64d%I64d%I64d",&m[i],&a[i][0],&a[i][1]);
            }
                cnt=n-1;
                flag=true;
               for(i=0;i<cnt&&flag;i++)
                for(j=i+1;j<n&&flag;j++)
               {
                   if(m[i]==m[j]&&(a[i][1]<a[j][0]||a[i][0]>a[j][1]))
                   continue;
                   else if(m[i]==m[j])
                   {
                       flag=false;break;
                   }
                   if(m[i]>m[j])
                         g=gcd(m[i],m[j]);
                   else  g=gcd(m[j],m[i]);
                   mi=a[i][0]-a[j][1];
                   ma=a[i][1]-a[j][0];
                   if(mi==0||ma==0||(mi<0&&ma>0))
                   {
                      flag=false;break;
                   }
                   if(mi%g==0||ma%g==0)
                   {
                      flag=false;break;
                   }
                   if((ma-mi+1)>=g)
                   {
                      flag=false;break;
                   }
                   ys[0]=(mi/g)*g+g;
                   if(ma-ys[0]>=0)
                   {
                      flag=false;break;
                   }
               }
          if(flag) printf("Can Take off\n");
                else printf("Cannot Take off\n");
       }
return 0;
}

反思:其实题目就是暴力判断两个同余方程有没有解的问题,可以很容易地转化到一个二元一次不定方程有没有解的问题,但是题目的特殊之处在于方程的常数项是一个范围而不是一个具体的数目,这个可以分几种情况讨论,情况压缩的不一样的话,可能运行时间略有波动,如果没有考虑全面,就会WA掉,一开始就WA了,因为在处理一种情况时判断错误了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值