题意:
给出n组x,y,z。判断是否存在一个id使得id%x1∈(y1,z1),id%x2∈(y2,z2)
设 a=id/x1 b=id/x2
则 id-a*x1=u id-b*x2=v -> bx2-ax1=u-v
则若 (u-v)%gcd(x2,x1) 成立则世界末日
#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"iostream"
using namespace std;
struct oo
{
int x,y,z;
} o[1234];
int gcd(int x, int y)
{
return y?gcd(y,x%y):x;
}
int main()
{
int n;
while(cin>>n)
{
int i,j;
int f=1;
for(i=0; i<n; i++)
{
scanf("%d%d%d",&o[i].x,&o[i].y,&o[i].z);
}
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
int a,b,tep;
int t;
a=min(o[i].y-o[j].z,o[i].z-o[j].y);
b=max(o[i].y-o[j].z,o[i].z-o[j].y);
tep=gcd(o[i].x,o[j].x);
t=a%tep;
if(t<0)
{
if(b>=a-t)
{
f=0;
break;
}
}
else if(t==0)
{
f=0;
break;
}
else
{
if(b>=a+(tep-t))
{
f=0;
break;
}
}
}
if(!f) break;
}
puts(f?"Can Take off":"Cannot Take off");
}
}