HDOJ 4596 Yet another end of the world【数学】
来源:互联网 发布:孙悟空法力 知乎 编辑:程序博客网 时间:2024/05/17 07:06
这个题题意简直不忍吐槽,好难读啊
其实是个数学题:问对于题目给的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;}
0 0
- HDOJ 4596 Yet another end of the world【数学】
- 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 4596Yet another end of the world(GCD)
- HDU-4596 Yet another end of the world (数论)
- HDU 4596 Yet another end of the world (拓展欧几里得)
- NJUST 1747 Yet another end of the world(13年南京邀请赛-K题-数学)
- HDU4596 Yet another end of the world 扩展欧几里德性质
- HDU 4569——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)(二进制进位次数和)
- PHP匿名函数
- 【网络编程】TCP有关函数
- redis 配置的说明
- 插入排序
- 配置机器:win10 + ubuntu16.04 + gtx1080
- HDOJ 4596 Yet another end of the world【数学】
- maven 目录结构
- JS干货--拷贝与继承
- Python 是否是下一个 PHP?为什么?
- 4-2 顺序表操作集 (20分)
- 嵌入式 Linux --C语言
- 【水题】hdoj1335 Basically Speaking
- 使用CAShapeLayer来实现圆形图片加载动画
- 数据结构看书笔记(十)—— 求最短路径问题之--迪杰斯特拉(Dijkstra)算法和弗洛伊德(Floyd)算法