codeforces gym 100463I Yawner
//这题挂得让我怀疑我最近是不是做了什么坏事
题意:一个人有两个集合,先在其中一个集合选一个数x,然后向右走x布,然后再在另一个集合里选一个数y,向左走y步,问是否能走完数轴上所有点。
解:显然是求gcd(ai-bj)的值是不是1,然后有gcd(ai-bj)=gcd(ai-b1,ai-b2,ai-b3,........)=gcd(ai-b1,b2-b1,b3-b1,b4-b1.....)=gcd(gcd(ai-b1),gcd(bj-b1)),然后就可以把a,b分开求了。另外假如求出来gcd值是2,那么要特殊讨论a中是否有奇数,即 即我们先前的假设是步数一样,但实际上a可以比b多走一步。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string>
#define LL long long const int MAXN=;
const int MAXM=;
const int INF=; using namespace std; int a[MAXN],b[MAXN];
int n,m,cas=; int gcd(int a,int b){
if (b==) return a;
return gcd(b,a%b);
} bool check(int x){
if (x>) return ;
bool flag=;
for (int i=;i<n;i++){
if (a[i]&) flag=true;
}
if (x== && !flag) return ;
return ;
} int main(){
while (scanf("%d%d",&n,&m)==){
if (n== && m==) break;
cas++;
for (int i=;i<n;i++) scanf("%d",&a[i]);
for (int i=;i<m;i++) scanf("%d",&b[i]);
sort(a,a+n);
sort(b,b+m);
if (a[n-]<b[] || a[]>b[m-]){
printf("Case %d: YES\n",cas);
continue;
}
int ans=a[]-b[];
for (int i=;i<n;i++) ans=gcd(ans,a[i]-b[]);
for (int i=;i<m;i++) ans=gcd(ans,b[i]-b[]);
if (!check(abs(ans))){
printf("Case %d: YES\n",cas);
}
else{
printf("Case %d: NO\n",cas);
}
}
return ;
}
/*
2 2
1
3
1
3 2 5
10
20
1
2
3
4
5
3 3
3
6
9
3
6
9
2 2
1
2
1
2
0 0
*/
codeforces gym 100463I Yawner的更多相关文章
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
- codeforces Gym 100187J J. Deck Shuffling dfs
J. Deck Shuffling Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
随机推荐
- python处理.seq文件
# Deal with .seq format for video sequence # Author: Kaij # The .seq file is combined with images, # ...
- rc.local自启动学习
在CentOS系统下,主要有三种方法设置自己安装的程序开机启动.1.把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd. #!/bin/sh # # ...
- python每次处理一个字符的三种方法
python每次处理一个字符的三种方法 a_string = "abccdea" print 'the first' for c in a_string: print ord(c) ...
- C语言随笔_fopen
有同学问我,以下代码会输出“===”,为什么呀? if( (fp = fopen("data.dat","r"))==NULL){ printf("= ...
- Count Primes 解答
Question Count the number of prime numbers less than a non-negative number, n. Solution 1 Naive way, ...
- (step6.1.3)hdu 1875(畅通工程再续——最小生成树)
题目大意:本题是中文题,可以直接在OJ上看 解题思路:最小生成树 1)本题的关键在于把二维的点转化成一维的点 for (i = 0; i < n; ++i) { scanf("%d%d ...
- python-MySQL库简单安装
1 raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_c ...
- MSSQL 常用内置函数
一.判断表是否存在 IF objectproperty(object_id(@tableName),'IsUserTable') IS NOT NULL PRINT '存在' ELSE PRINT ' ...
- 【HTML+CSS】浅谈:相对定位与绝对定位
相对定位和绝对定位 ·定位标签:position ·包括属性:relative(相对) absolute(绝对) 1.position:relative; 假设对一个元素进行相对定位.首先它将出如今 ...
- 创建GIF loading图片
第一步 新建一个宽80PX 高10PX的文档 第二步 做8个宽8PX的方格 黄色色值#e7a521 红色色值#ff0000(可根据自己的喜好设定) 第三步 复制7个层(共8个图层)每个图层相应改变红色 ...