HDU4596Yet another end of the world(扩展欧几里得)
来源:互联网 发布:08最新电影源码 编辑:程序博客网 时间:2024/06/05 20:37
题意:
给定一系列的虫洞,每个虫洞都有自己的x,y,z,当你的 id 对 x 取余后结果落在[ y,z ]区间内,则会被吸引,被两个或两个以上的虫洞吸引会有危险,求能否宇宙飞船能否起飞。
分析:
枚举每两个虫洞,有
id - k1 * x1 = u
id - k2 * x2 = v
其中k1与k2分别为 id / x1 与 id / x2,u与v分别为求余后的结果。
两式相减得 k2 * x2 - k1 * x1 = u - v
根据扩展欧几里得,判断 u - v 的取值是否能取到 gcd(x1, x2) 的整数倍即可
而 u 的范围为 [ y1, z1 ] ,v 的范围为 [ y2, z2 ],则 u - v 的范围为 [ y1 - z2,z1 - y2 ]。
假设范围为[ a,b ],gcd为 t 。
1、若a%t == 0 || b % t == 0,那么符合条件;
2、排除掉1的情况下,若a / t != b / t,那么也符合条件,因为若满足,则a与b中必定存在至少一个数能够对 t 取余为0。
#include<bits/stdc++.h>using namespace std;#define N 1005int x[N], y[N], z[N], n;bool isok(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 solve(){ for(int i=1; i<=n; i++) { for(int j=i+1; j<=n; j++) { int gcd=__gcd(x[i], x[j]); if(isok(gcd, y[i]-z[j], z[i]-y[j])) return true; } } return false;}int main(){ while(scanf("%d", &n)!=EOF) { for(int i=1; i<=n; i++) scanf("%d%d%d", &x[i], &y[i], &z[i]); if(solve()) puts("Cannot Take off"); else puts("Can Take off"); } return 0;}
阅读全文
0 0
- HDU4596Yet another end of the world(扩展欧几里得)
- HDU 4596 - Yet another end of the world(扩展欧几里得)
- hdu Yet another end of the world(扩展欧几里得定理推论)
- [欧几里得] hdu 4596 Yet another end of the world
- HDU 4596 Yet another end of the world (拓展欧几里得)
- HDU4596 Yet another end of the world 扩展欧几里德性质
- HDU 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 (数论)
- 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 4569——Yet another end of the world
- HDOJ 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题-数学)
- OpenCV学习之六: 使用方向梯度直方图估计图像旋转角度
- poj 2449 Remmarguts' Date (A*,k短路)
- 软件需求工程 课堂笔记5
- C++11多线程原子类型
- Python小程序 -- 人民币小写转大写辅助工具
- HDU4596Yet another end of the world(扩展欧几里得)
- 1030. 完美数列(25)--PAT乙级
- 在windows10上安装tensorflow(GPU)
- java 实现排列组合Permutation and Combination和链式不相邻排列组合和环形不相邻排列
- HDU
- java连接oracle数据库代码
- 基于CentOS的MYSQL基础介绍
- CentOS7设置定时任务 每隔30分钟执行一次命令
- 软件需求 目录