HDU 4596Yet another end of the world(GCD)
来源:互联网 发布:阿里云香港翻墙 编辑:程序博客网 时间:2024/05/16 17:39
题意:给出N行 x,l,r。如果有数ID%x1属于[l1,r1]而且ID%x2属于[l2,r2]那么Cannot Take off,否则Can Take off。
分析:假设有这么一个数ID使得“cannot.....”,那么:
ID=x1*a+u ①
且ID=x2*b+v ②
②-①:x2*b-x1*a=v-u ③
此时 l2-r1<=x2*b-x1*a<=r2-l1
如果③有解则gcd(x1,x2)的n倍在区间[l2-r1,r2-l1]。
有解则说明假设成立,否则假设不成立ID则使得“can....”。
#include<iostream>#include<string>#include<stdio.h>#include<string.h>#include<vector>#include<math.h>#include<queue>#include<map>#include<set>#include<algorithm>using namespace std;#define MAXN 1005#define LL long long#define INF 0x7f7f7f7fconst double eps = 1e-10;LL n;struct node{ LL x,l,r;}a[MAXN],tx,ty;LL fun(LL l1,LL r1,LL l2,LL r2){ if(l2>=l1&&l2<=r1||r2>=l1&&r2<=r1) return 1; if(l1>=l2&&l1<=r2||r1>=l2&&r1<=r2) return 1; return 0;}LL gcd(LL a,LL b){ return b==0?a:gcd(b,a%b);}LL ok(LL i,LL j){ LL ll,rr; if(a[i].x>a[j].x) { tx=a[i]; ty=a[j]; } else tx=a[j],ty=a[i]; if(fun(tx.l,tx.r,ty.l,ty.r)) return 0; LL d=gcd(tx.x,ty.x); if(ty.r<tx.l) { ll=tx.l-ty.r; rr=tx.r-ty.l; } else { ll=ty.l-tx.r; rr=ty.r-tx.l; } if(rr-ll+1>=d) return 0; else { LL modl=ll%d; LL modr=rr%d; if(modl==0) return 0; else if(modl<modr) { return 1; } else if(modr<modl) { return 0; } else if(modl==modr) { if(modl==0) return 0; } }}int main(){ LL j,i; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) scanf("%lld%lld%lld",&a[i].x,&a[i].l,&a[i].r); LL ans=0; for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(!ok(i,j)) { ans=1; break; } } if(ans==1)break; } if(ans==1) puts("Cannot Take off"); else puts("Can Take off"); } return 0;}
0 0
- HDU 4596Yet another end of the world(GCD)
- HDU 4596 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(数论)
- HDU 4596 Yet another end of the world
- [欧几里得] hdu 4596 Yet another end of the world
- HDU OJ 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 4569——Yet another end of the world
- Yet another end of the world
- HDOJ 4596 Yet another end of the world【数学】
- Spring MVC @JsonView实现在消息转换器中过滤数据
- angular js自定义指令
- iOS高德地图 初始化 重定义比例尺
- for... in...
- Bootstrap 布局
- HDU 4596Yet another end of the world(GCD)
- jquery ajax之loading效果
- POJ 2243 - Knight Moves
- 轮廓的查找、表达、绘制、特性及匹配
- iOS Grand Central Dispatch (GCD) 的一般使用详解
- svn添加到visual项目中
- javascript原生cookie
- 数据库基本操作(1)
- 浅谈Spark应用程序的性能调优