hdu4596

Yet another end of the world

http://acm.hdu.edu.cn/showproblem.php?pid=4596

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

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

题意

如果存在一个飞船的ID满足ID%X1在Y1到Z1之间并且满足ID%X2在Y2到Z2,则飞船会被撕裂,无法起飞。

解析

最简单的拓展欧几里得拓展+二元一次不定方程。
首先假设一个数m,则有m%x1=r1,m%x2=r2;y1<=r1<=z1&&y2<=r2<=z2,
由m%x1=r1,m%x2=r2;可得m=x1*k1+r1,m=x2*k2+r2,得x1*k1-x2*k2=r1-r2,r1-r2在1y2-z1到z2-y1之间,所以判断gcd(x1,x2)能否被一个在y2-z1到z2-y1之间的数整除即可。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int x,y,z;
}sum[1005];
int gcd(int x,int y)
{
	return x%y==0?y:gcd(y,x%y);
}
int slo(int a,int b,int l,int r)
{
	if(r

你可能感兴趣的:(HDU)