题目大意:给定若干组x,y,z,问是否能找到一个整数d,使得至少两组x,y,z满足y≤d%x≤z。
解题思路:首先枚举出两组x,y,z。
然后判断这两组是否能找到一个d,使得满足题目条件。
现在假设a、b,有a*x1+y1≤d≤a*x1+z1和b*x2+y2≤d≤b*x2+z2;
若两段区间有交集,必有a*x1+y1≤b*x2+z2且b*x2+y2≤a*x1+z1;
化简得a*x1-b*x2≤z2-y1 且a*x1-b*x2≥y2-z1;
若a,b有整数解,根据拓展欧几里得定理ax1+bx2=u有整数解的情况为u/gcd(x1,x2)==0;
所以若存在y2-z1≤u≤z2-y1,使得u/gcd(x1,x2)==0即可。
// Created by Chenhongwei on 2016-05-01 Sunday 12:24
// Copyright (c) 2016 Chenhongwei. All rights reserved.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#define root 1,n,1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+100;
typedef long long ll;
typedef unsigned long long ull;
ll n;
ll a[1100],b[1100],c[1100];
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
bool check(int x,int y)
{
ll tt=gcd(a[x],a[y]);
ll left=b[y]-c[x];
ll right=c[y]-b[x];
if(left%tt==0||right%tt==0)
return true;
if(left<=0&&right>=0)
return true;
if(right/tt-left/tt>=1)
return true;
return false;
}
int main()
{
//ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%lld",&n)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
bool flag=0;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
if(check(i,j))
{
flag=1;
break;
}
if(flag)
break;
}
if(!flag)
puts("Can Take off");
else
puts("Cannot Take off");
}
return 0;
}