HDU 4596 Yet another end of the world (数学,扩展欧几里德)
题意:给出n组x,y,z。判断是否存在一个id使得id%x1∈(y1,z1),id%x2∈(y2,z2)。
析:
设 id/x1=a , id/x2=b ,则
id-a*x1=u; (1)
id-b*x2=v; (2)
(1)-(2)得 一阶不定方程: bx2-ax1=u-v .
方程可解性为是否存在 (u-v) 是gcd(x1,x2)的整数倍。
那么也就是判断y[x1]-z[x2], z[x1]-y[x2],这就是范围,然后在判断是的时候,如果两个端点能够整除,就返回真,如果两个端点除以g,
不相等,那么一定有一个数能整除g。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int maxn = 1000 + 5;
int x[maxn], y[maxn], z[maxn];
int n; bool judge(int g, int l, int r){
if(l % g == 0 || r % g == 0) return true;
return l / g != r / g;
} bool solve(){
for(int i = 0; i < n; ++i){
for(int j = i+1; j < n; ++j){
int g = __gcd(x[i], x[j]);
if(judge(g, y[i]-z[j], z[i]-y[j])) return true;
}
}
return false;
} int main(){
while(scanf("%d", &n) == 1){
for(int i = 0; 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;
}
HDU 4596 Yet another end of the world (数学,扩展欧几里德)的更多相关文章
- HDU 1098 Ignatius's puzzle 费马小定理+扩展欧几里德算法
题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为 ...
- hdu 1576 A/B (扩展欧几里德简单运用)
http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others) Memory Lim ...
- HDU 2669 Romantic 扩展欧几里德---->解不定方程
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2669 Romantic(扩展欧几里德)
题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...
- HDU - 6409:没有兄弟的舞会(数学+思维)
链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...
- hdu 4300 Clairewd’s message(具体解释,扩展KMP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. ...
- HDU 6108 小C的倍数问题 【数学】 (2017"百度之星"程序设计大赛 - 初赛(A))
小C的倍数问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 5768Lucky7(多校第四场)容斥+中国剩余定理(扩展欧几里德求逆元的)+快速乘法
地址:http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 1576 A/B(扩展欧几里德变形)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但因为A非常大,我们仅仅给出n ...
随机推荐
- [原创] - C#编程大幅提高OUTLOOK的邮件搜索能力!
使用OUTLOOK, 你有没有遇到过上图的问题? 多达18419封邮件! 太多了, 每次想找一个邮件都非常耗时, 想办法解决这个问题成了一件非常紧迫的事情. 利用MS Search当然可以, 但是它太 ...
- BZOJ 4690 Never Wait for Weights
带权并查集23333333 注意dis[x]+=dis[fath[x]. #include<iostream> #include<cstdio> #include<cst ...
- codevs 4927 线段树练习5
赶在期末考试之前把这道傻逼题调了出来. #include<iostream> #include<cstdio> #include<cstring> #include ...
- 给产品经理讲技术,不得不懂的TCP和UDP
TCP/IP协议,你一定经常听说吧,其中TCP(Transmission Control Protocol)称为传输控制协议,IP(Internet Protocol)称为因特网互联协议,好吧,这都是 ...
- 【转】shell脚本调试(bash trap support bashdb )
原文网址:http://zhu8337797.blog.163.com/blog/static/170617549201122512712136/ 命 令 选 项 功 能 bash –x 脚本名 回显 ...
- DOJO 如何清空表单
在Dojo里,清空表单非常简单 在设置好了相关的环境之后,只要设置dom.byId('formid').reset(); / dijit.byId('formid').reset; Jqu ...
- 查看MySQL的警告信息
在王MySQL数据库导入数据的时候经常会出现警告,这些警告很容易被忽视,今天到数据的时候突然想看看警告的内容是什么,百度了一下mysql查看警告的命令 show warnings; 命令很简明,一查看 ...
- LoadRunner error -27728
错误现象1:Action.c(16): Error -27728: Step download timeout (120 seconds) has expired whendownloading no ...
- linux笔记_20150825_linux下的软件工具唠叨下
这些都是书上看到的,有些工具我也没有完全用过.先记下来再说.闲着也是闲着. 1.linux下常见的语言及编程环境:c/c++/java/perl/fortan等. 2.图形环境:gnome/kde/g ...
- just test Gson
just test Gson code package com.qilin.test; import com.google.gson.Gson; import org.apache.commons.l ...