HDOJ 4596 Yet another end of the world【数学】
2016-11-07 20:11
537 查看
这个题题意简直不忍吐槽,好难读啊
其实是个数学题:问对于题目给的x【i】,y【i】,z【i】
是否能够找到一个数ID,使得:
ID%x【i】在区间【yi,zi】且ID%x【j】在区间【yj,zj】之中,i!=j
如果找到了,输出
Cannot Take off
否则输出
Can Take off
拿样例来分析:第一个,很明显,因为除数是同一个数7,余数不同,那么肯定找不到这样的ID:输出Can
第二个:有7有9,是互质的。那么我们很容易构造出来一个:7*9+2=65,找到了一个,那么输出Cannot
所以,我们需要找到的是:
ID%u=a
ID%v=b
这种ID值
那么根据同余理论,判断是不是gcd(u,v)的倍数就好了
那么两个区间怎么判断呢?
加上符号,变成:y【i】-z【j】,z【i】-y【j】然后去处理就好了
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+50;
int n;
int x[maxn],y[maxn],z[maxn];
bool ok(int gcd,int L,int R){
if (L%gcd==0||R%gcd==0) return true;
if (L<0&&R>0) return true;
if (R/gcd-L/gcd>0) return true;
return false;
}
bool check(){
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if (ok(__gcd(x[i],x[j]),y[i]-z[j],z[i]-y[j])) return false;
return true;
}
int main(){
//freopen("input.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++)
scanf("%d%d%d",&x[i],&y[i],&z[i]);
if (check()) puts("Can Take off");
else puts("Cannot Take off");
}
return 0;
}
其实是个数学题:问对于题目给的x【i】,y【i】,z【i】
是否能够找到一个数ID,使得:
ID%x【i】在区间【yi,zi】且ID%x【j】在区间【yj,zj】之中,i!=j
如果找到了,输出
Cannot Take off
否则输出
Can Take off
拿样例来分析:第一个,很明显,因为除数是同一个数7,余数不同,那么肯定找不到这样的ID:输出Can
第二个:有7有9,是互质的。那么我们很容易构造出来一个:7*9+2=65,找到了一个,那么输出Cannot
所以,我们需要找到的是:
ID%u=a
ID%v=b
这种ID值
那么根据同余理论,判断是不是gcd(u,v)的倍数就好了
那么两个区间怎么判断呢?
加上符号,变成:y【i】-z【j】,z【i】-y【j】然后去处理就好了
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+50;
int n;
int x[maxn],y[maxn],z[maxn];
bool ok(int gcd,int L,int R){
if (L%gcd==0||R%gcd==0) return true;
if (L<0&&R>0) return true;
if (R/gcd-L/gcd>0) return true;
return false;
}
bool check(){
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if (ok(__gcd(x[i],x[j]),y[i]-z[j],z[i]-y[j])) return false;
return true;
}
int main(){
//freopen("input.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++)
scanf("%d%d%d",&x[i],&y[i],&z[i]);
if (check()) puts("Can Take off");
else puts("Cannot Take off");
}
return 0;
}
相关文章推荐
- [HDOJ4596] Yet another end of the world(数学,gcd,二元一次方程)
- HDU 4596 Yet another end of the world (数学,扩展欧几里德)
- HDU 4596 Yet another end of the world(解一阶不定方程)
- HDU 4596 Yet another end of the world(一阶不定方程是否可解,gcd)
- hdu 4596 Yet another end of the world 线性同余方程组
- HDU 4596 J - Yet another end of the world(数论)
- HDU 4596 Yet another end of the world (扩展欧几里德)
- NJUST 1747 Yet another end of the world(13年南京邀请赛-K题-数学)
- [欧几里得] hdu 4596 Yet another end of the world
- HDU 4596 - Yet another end of the world(扩展欧几里得)
- hdu 4596 Yet another end of the world (一阶不定方程可解性 )
- HDU-4596 Yet another end of the world (数论)
- hdu 4596 Yet another end of the world(数论)
- Hdu 4596 Yet another end of the world(数论)
- HDU 4596 Yet another end of the world
- HDU 4596 Yet another end of the world (拓展欧几里得)
- HDU 4596 Yet another end of the world(GCD)
- HDU 4596 (Yet another end of the world)(二进制进位次数和)
- HDU4596 Yet another end of the world 扩展欧几里德性质
- HDU 4569——Yet another end of the world