The question hangs on me to wonder if I've done anything bad lately.
Test instructions: A person has two sets, first select a number x in one of the sets, then go to the right x cloth, and then select a number y in another set, go to the left Y step, ask whether you can go through all the points on the axis.
Solution: It is clear that the value of GCD (AI-BJ) is not 1, then there is 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)), then you can separate a, B. In addition, if the GCD value is 2, then a special discussion of whether a is an odd number, that is, our previous assumption is the same as the steps, but in fact a can go one step more than B.
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5#include <cstring>6#include <cstdlib>7#include <queue>8#include <vector>9#include <map>Ten#include <stack> One#include <string> A #defineLL Long Long - - Const intmaxn=100007; the Const intmaxm=0; - Const intinf=2000000000; - - using namespacestd; + - intA[MAXN],B[MAXN]; + intn,m,cas=0; A at intgcdintAintb) { - if(b==0)returnA; - returnGCD (b,a%b); - } - - BOOLCheckintx) { in if(x>2)return 0; - BOOLflag=0; to for(intI=0; i<n;i++){ + if(a[i]&1) flag=true; - } the if(x==2&&!flag)return 0; * return 1; $ }Panax Notoginseng - intMain () { the while(SCANF ("%d%d", &n,&m) = =2){ + if(n==0&& m==0) Break; Acas++; the for(intI=0; i<n;i++) scanf ("%d",&a[i]); + for(intI=0; i<m;i++) scanf ("%d",&b[i]); -Sort (a,a+n); $Sort (b,b+m); $ if(a[n-1]<b[0] || a[0]>b[m-1]){ -printf"Case %d:yes\n", CAs); - Continue; the } - intans=a[0]-b[0];Wuyi for(intI=1; i<n;i++) ANS=GCD (ans,a[i]-b[0]); the for(intI=1; i<m;i++) ANS=GCD (ans,b[i]-b[0]); - if(!Check (abs (ANS))) { Wuprintf"Case %d:yes\n", CAs); - } About Else{ $printf"Case %d:no\n", CAs); - } - } - return 0; A } + /* the 2 2 - 1 $ 3 the 1 the 3 the the 2 5 - Ten in - the 1 the 2 About 3 the 4 the 5 the 3 3 + 3 - 6 the 9Bayi 3 the 6 the 9 - 2 2 - 1 the 2 the 1 the 2 the 0 0 - */View Code
Codeforces Gym 100463I Yawner