HDU 4596 - Yet another end of the world(扩展欧几里得)
来源:互联网 发布:淘宝李宁是真的吗 编辑:程序博客网 时间:2024/05/16 16:16
题意:给定一系列的虫洞,每个虫洞都有自己的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<cstdio>#include<cstring>#include<cctype>#include<cstdlib>#include<cmath>#include<iostream>#include<sstream>#include<iterator>#include<algorithm>#include<string>#include<vector>#include<set>#include<map>#include<deque>#include<queue>#include<stack>#include<list>typedef long long ll;typedef unsigned long long llu;const int MAXN = 100 + 10;const int MAXT = 1000 + 10;const int INF = 0x7f7f7f7f;const double pi = acos(-1.0);const double EPS = 1e-6;using namespace std;ll gcd(ll m, ll n){ if(n == 0) return m; return gcd(n, m % n);}ll a, b, x[MAXT], y[MAXT], z[MAXT];int n;inline bool is_attract(ll t, ll u, ll v){ if(u % t == 0 || v % t == 0) return true; return u / t != v / t;}bool solve(){ for(int i = 0; i < n; ++i) for(int j = i + 1; j < n; ++j){ ll t = gcd(x[i], x[j]); if(is_attract(t, y[j] - z[i], z[j] - y[i])) return false; } return true;}int main(){ while(scanf("%d", &n) == 1){ for(int i = 0; i < n; ++i) scanf("%I64d%I64d%I64d", x + i, y + i, z + i); if(solve()) printf("Can Take off\n"); else printf("Cannot Take off\n"); } return 0;}
0 0
- 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 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 (扩展欧几里德)
- 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
- HDU4596Yet 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 4596 Yet another end of the world (一阶不定方程可解性 )
- hdu 4596 Yet another end of the world (一阶不定方程可解性 )
- HDU 4596 Yet another end of the world(一阶不定方程是否可解,gcd)
- 17.1.1.9 Introducing Additional Slaves to an Existing Replication Environment 引入额外的Slaves 到一个存在的复制
- ssm遇到css样式和js加载不出来
- 读书笔记二——第一章《面向服务的体系架构SOA》上
- C++虚函数、纯虚函数、虚基类
- 【HDU5740 2016 Multi-University Training Contest 2G】【二分图染色+费用流+路径输出】Glorious Brilliance 最少交换次数使得相邻点颜色
- HDU 4596 - Yet another end of the world(扩展欧几里得)
- QQ与共享
- 解决Visual Studio 2010新建工程时出现『1>LINK : fatal error LNK1123: failure during conversion to COFF: file in
- 关于IIS 7.5 限制连接数与流量限制模块
- 校园网(需支持IPV6)翻**访问*谷歌google
- JS+CSS 实现 悬停广告
- 个人学习笔记--sed命令(基础篇)
- HTMLCSS基础-基础选择符
- DAY13:leetcode #27 Remove Element