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 ...
随机推荐
- 自定义searchview的编辑框,搜索按钮,删除按钮,光标等
//指定某个私有属性 Field mSearchHintIconField = argClass.getDeclaredField("mSearchHintIcon"); mSea ...
- cf471B MUH and Important Things
B. MUH and Important Things time limit per test 1 second memory limit per test 256 megabytes input s ...
- Jquery时间快捷控件(Jtime)配置v1.0
1.脚本代码行 /** * @title 时间工具类 * @note 本类一律违规验证返回false * @author {boonyachengdu@gmail.com} * @date 2013- ...
- Libgdx开发ios游戏
今天亲自尝试了LibGDX如何开发ios游戏, 必须条件: 1:mac操作系统,mac下必须安装Xcode 好像ios开发必须在mac操作系统下 2:mac下安装eclipse 3:eclip ...
- 在Linux下如何创建LVM及LVM创建过程
Linux LVM创建过程:(我用的是Centos6.8) 一.准备工作: LVM可以的创建可以在系统安装的过程中创建,也可以在安装完系统之后再创建建,都是可以的,我的是在系统安装完之后创建的,具体的 ...
- C语言结构体的内存对齐问题
在C语言开发当中会遇到这样的情况: #include <stdio.h> struct test { int a; char b; }; int main(int argc, const ...
- java连接oracle数据库详细代码
详细代码: import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;imp ...
- JSP中的include的两种用法
1.两种用法 <%@ include file=” ”%> <jsp:include page=” ” flush=”true”/> 2.用法区别 (1)执行时间上区别 < ...
- Ubuntu14.04搭建安装svnserver
前两天,公司准备搭建一个svnserver,供大家使用.于是.就先装了一个Ubuntu系统,然后搭建了svnserver的环境.以下把svn搭建的详细过程描写叙述下: 1.安装svn sudo apt ...
- office 文件在网页中显示
1.如何在网页上显示word和excel a.可以使用office组件或aspose将word 和excel 转换为pdf 然后在网页上打开pdf,但是效果不是很好 .比如说excel 多个工作薄不是 ...