HDU4596 Yet another end of the world 扩展欧几里德性质
2017-06-15 09:51
519 查看
这题坑了,我真该吃翔啊,竟然一開始方程设错了并且没有去想连列的问题,我真是坑货,做不出就该又一次理一下嘛。操蛋。
题意:给了N组x,y,z然后 问你是否存在两个或者两个以上的id,是的 id%x的值在区间[y,z]之间。若有则输出Cannot Take off
否则你懂得
依据题意 那么 列出 :
a*x1 + y1 <= id <= a*x1 + z1
b * x2 + y2 <= id <= b*x2 + z2,
如果有解的话,那么这两个区间肯定有反复部分。,那么继续推得:
a*x1 <= b*x2 + z2 和 b *x2 + y2 <= a*x1 + z1
化简能够得到
a* x1 - b* x2 <= z2 - y1 1号式子
b * x2 - a*x1 <= z1 - y2 2号式子
为了统一 再把2号变成
a*x1 - b*x2 <= y2 - z1
然后看到这个应该就要想到扩展欧几里德,若存在非负的且不都为0整数a,b,必定存在整数对 x,y使得 gcd(a,b) = a*x + b*y,
应用到这道题目上也就是 要求 gcd(x1,x2) = a*x1 + (- b*x2) 这个式子存在解,这个式子的值同一时候又是 z2 - y1所以实际上就是转化成了
gcd(x1,x2)与 z2 - y1得有整数倍的关系 ,意思就是 (z2-y1)%gcd(x1,x2) == 0。注意是取模。居然看到有篇题解写的是除号,做完想看看别人做法时看到这里坑了我一下,还以为我推的有问题呢,原来是他自己写错了,问题是居然另外有人的题解 直接复制了 他的解析,唉~~~~~
同一时候对于式子2我们也能够推到 (y2 - z1)%)gcd(x1,x2) == 0 这两个当中随意一个满足就可以,区间覆盖部分 不用严格包括,语文不太好说不清楚,反正留给自己长脑子的
题目给出了N组。N的范围为1000,直接扫两层暴力来推断就能够了。
我的推断是否整除部分是:
其它人的题解推断部分是:
并且眼下为止我看到的网上的题解的 全部人的推断部分 如出一辙啊,全都是如上述所看到的的那样。可是我少了以下那两个if推断过了,是题目数据太水了吗,以下两个推断我还这么没搞懂,是我这个弱菜漏了什么吗。路过有大神请教指点啊,
题意:给了N组x,y,z然后 问你是否存在两个或者两个以上的id,是的 id%x的值在区间[y,z]之间。若有则输出Cannot Take off
否则你懂得
依据题意 那么 列出 :
a*x1 + y1 <= id <= a*x1 + z1
b * x2 + y2 <= id <= b*x2 + z2,
如果有解的话,那么这两个区间肯定有反复部分。,那么继续推得:
a*x1 <= b*x2 + z2 和 b *x2 + y2 <= a*x1 + z1
化简能够得到
a* x1 - b* x2 <= z2 - y1 1号式子
b * x2 - a*x1 <= z1 - y2 2号式子
为了统一 再把2号变成
a*x1 - b*x2 <= y2 - z1
然后看到这个应该就要想到扩展欧几里德,若存在非负的且不都为0整数a,b,必定存在整数对 x,y使得 gcd(a,b) = a*x + b*y,
应用到这道题目上也就是 要求 gcd(x1,x2) = a*x1 + (- b*x2) 这个式子存在解,这个式子的值同一时候又是 z2 - y1所以实际上就是转化成了
gcd(x1,x2)与 z2 - y1得有整数倍的关系 ,意思就是 (z2-y1)%gcd(x1,x2) == 0。注意是取模。居然看到有篇题解写的是除号,做完想看看别人做法时看到这里坑了我一下,还以为我推的有问题呢,原来是他自己写错了,问题是居然另外有人的题解 直接复制了 他的解析,唉~~~~~
同一时候对于式子2我们也能够推到 (y2 - z1)%)gcd(x1,x2) == 0 这两个当中随意一个满足就可以,区间覆盖部分 不用严格包括,语文不太好说不清楚,反正留给自己长脑子的
题目给出了N组。N的范围为1000,直接扫两层暴力来推断就能够了。
我的推断是否整除部分是:
int cal(int a,int b,int c) { if(c%a == 0 || b%a == 0)return 1;//不等式相等情况时的整除 return 0; }
其它人的题解推断部分是:
bool isok(int t,int le,int ri) { int i,j; if(le%t==0||ri%t==0) return true ; if(le<0&&ri>=0) return true ; if(ri/t-le/t>0) return true ; return false ; }
并且眼下为止我看到的网上的题解的 全部人的推断部分 如出一辙啊,全都是如上述所看到的的那样。可是我少了以下那两个if推断过了,是题目数据太水了吗,以下两个推断我还这么没搞懂,是我这个弱菜漏了什么吗。路过有大神请教指点啊,
#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>
#define ll long long
#define eps 1e-8
#define inf 0xfffffff
const ll INF = 1ll<<61;
using namespace std;
//vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p;
const int N = 1000 + 5;
int x
,y
,z
;
void init() {
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
memset(z,0,sizeof(z));
}
int gcd(int a,int b) {
return b==0?a:gcd(b,a%b);
}
int cal(int a,int b,int c) { if(c%a == 0 || b%a == 0)return 1;//不等式相等情况时的整除 return 0; }
int main() {
int n;
while(scanf("%d",&n) == 1) {
init();
for(int i=0;i<n;i++)
scanf("%d %d %d",&x[i],&y[i],&z[i]);
bool flag = false;
for(int i=0;i<n;i++) {
for(int j=i + 1;j<n;j++) {
int tmp = gcd(x[i],x[j]);
if(cal(tmp,z[j] - y[i],y[j] - z[i])) {
flag = true;
}
}
}
if(flag)
puts("Cannot Take off");
else
puts("Can Take off");
}
return 0;
}
相关文章推荐
- HDU4596 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 4596 Yet another end of the world (拓展欧几里得)
- HDOJ 4596 Yet another end of the world【数学】
- HDU 4569——Yet another end of the world
- NJUST 1747 Yet another end of the world(13年南京邀请赛-K题-数学)
- 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 J - Yet another end of the world(数论)
- 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(GCD)
- K - Yet another end of the world(2013南京邀请赛K题)
- Yet another end of the world
- [欧几里得] hdu 4596 Yet another end of the world