Codeforces Round #268 (Div. 2 ),
Codeforces Round #268 (Div. 2) A. I Wanna Be the Guytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
There is a game called "I Wanna Be the Guy", consistingNLevels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass onlyPLevels of the game. And Little Y can pass onlyQLevels of the game. you are given the indices of levels Little X can pass and the indices of levels Little Y can pass. will Little X and Little Y pass the whole game, if they cooperate each other?
Input
The first line contains a single integerN(1 hour ≤ hourNLimit ≤ limit 100 ).
The next line contains an integerP(0 bytes ≤ bytesPLimit ≤ limitN) At first, then followsPDistinct integersA1, bytes,A2, middle..., middle ,...,AP(1 digit ≤ DigitAILimit ≤ limitN). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1N.
Output
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard! "(Without the quotes ).
Sample test (s) input
43 1 2 32 2 4
Output
I become the guy.
Input
43 1 2 32 2 3
Output
Oh, my keyboard!
Note
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4.
#include <iostream>#include <cstring>#include <cstdio>#include <set>using namespace std;int vis[110];int main(){int n,p,q;scanf("%d",&n);scanf("%d",&p);for(int i=0;i<p;i++){int x;scanf("%d",&x);vis[x]=1;}scanf("%d",&q);for(int i=0;i<q;i++){int x;scanf("%d",&x);vis[x]=1;}bool flag=true;for(int i=1;i<=n;i++)if(vis[i]==0){flag=false;break;}if(flag==true) puts("I become the guy.");else puts("Oh, my keyboard!");return 0;}
B. Chat Onlinetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Little X and Little Z are good friends. They always chat online. But both of them have schedules.
Little Z has fixed schedule. He always online at any moment of timeA1 andB1,A2 andB2,...,APAndBP(All borders random SIVE ). but the schedule of Little X is quite strange, it depends on the time when he gets up. if he gets up at time 0, he will be online at any moment of timeC1 andD1,C2 andD2,...,CQAndDQ(All borders random SIVE). But if he gets up at timeT, These segments will be shiftedT. They become [CIRegion + RegionT, Bytes,DIRegion + RegionT] (For allI).
If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of timeLAndR(Both borders random SIVE ). also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules ). how many integer moments of time from the segment [L, Bytes,R] Suit for that?
Input
The first line contains four space-separated integersP, Bytes,Q, Bytes,L, Bytes,R(1 hour ≤ hourP, Bytes,QLimit ≤ limit 50; 0 limit ≤ limitLLimit ≤ limitRLimit ≤ limit 1000 ).
Each of the nextPLines contains two space-separated integersAI, Bytes,BI(0 bytes ≤ bytesAILatency <latencyBILimit ≤00001000). Each of the nextQLines contains two space-separated integersCJ, Bytes,DJ(0 bytes ≤ bytesCJLatency <latencyDJLimit ≤ limit 1000 ).
It's guaranteed thatBILatency <latencyAIBetween + between 1 andDJLatency <latencyCJToken + token 1 for all validIAndJ.
Output
Output a single integer-the number of moments of time from the segment [L, Bytes,R] Which suit for online conversation.
Sample test (s) input
1 1 0 42 30 1
Output
3
Input
2 3 0 2015 1723 261 47 1115 17
Output
20
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;int p,q,l,r;struct TI{int from,end;}X[100],Z[100];int main(){cin>>p>>q>>l>>r;for(int i=0;i<p;i++){cin>>Z[i].from>>Z[i].end;}for(int i=0;i<q;i++){cin>>X[i].from>>X[i].end;}int ans=0;for(int t=l;t<=r;t++){bool flag=false;for(int i=0;i<q;i++){int Fr=X[i].from+t,To=X[i].end+t;for(int j=0;j<p;j++){if(Fr>Z[j].end) continue;if(To<Z[j].from) break;///crossint Left=max(Fr,Z[i].from);int Right=min(To,Z[i].end);if(Left>=Z[i].from&&Right<=Z[i].end){flag=true;break;}}if(flag==true) break;}if(flag==true) {ans++;}}cout<<ans<<endl;return 0;}
C. 24 Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he has Ted a new game.
Initially you have a sequenceNIntegers: 1, clerk 2, clerk..., clerk ,...,N. In a single step, you can pick two of them, let's denote themAAndB, Erase them from the sequence, and append to the sequence eitherARegion + RegionB, OrAAccept-Encoding-B, OrALimit × limitB.
AfterNPlease-Skip 1 steps there is only one number left. Can you make this number equal to 24?
Input
The first line contains a single integerN(1 digit ≤ DigitNLimit ≤ limit 105 ).
Output
If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes ).
If there is a way to obtain 24 as the result number, in the followingNLimits-limits 1 lines print the required operations an operation per line. Each operation shoshould be in form :"A Op B=C". WhereAAndBAre the numbers you 've picked at this operation;OpIs either "+", or "-", or "*";CIs the result of corresponding operation. Note, that the absolute valueCMustn't be greater than 1018. The result of the last operation must be equal to 24. Separate operator sign and equality sign from numbers with spaces.
If there are multiple valid answers, you may print any of them.
Sample test (s) input
1
Output
NO
Input
8
Output
YES8 * 7 = 566 * 5 = 303 - 4 = -11 - 2 = -130 - -1 = 3156 - 31 = 2525 + -1 = 24
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){int n;cin>>n;if(n<=3){puts("NO");}else{puts("YES");if(n==4){puts("1 + 2 = 3");puts("3 + 3 = 6");puts("4 * 6 = 24");}else if(n==5){puts("3 + 5 = 8");puts("8 - 2 = 6");puts("4 * 6 = 24");puts("1 * 24 = 24");}else{if((n-4)%2==0){puts("1 + 2 = 3");puts("3 + 3 = 6");puts("4 * 6 = 24");for(int i = 6;i<= n;i+=2){printf("%d - %d = 1\n",i,i-1);puts("1 * 24 = 24");}}else{puts("3 + 5 = 8");puts("8 - 2 = 6");puts("4 * 6 = 24");puts("1 * 24 = 24");for(int i = 7;i<=n;i+=2){printf("%d - %d = 1\n",i,i-1);puts("1 * 24 = 24");}}}}return 0;}
D. Two Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Little X hasNDistinct integers:P1, bytes,P2, middle..., middle ,...,PN. He wants to divide all of them into two setsAAndB. The following two conditions must be satisfied:
- If numberXBelongs to setA, Then numberAAccept-Encoding-XMust also belong to setA.
- If numberXBelongs to setB, Then numberBAccept-Encoding-XMust also belong to setB.
Help Little X divide the numbers into two sets or determine that it's impossible.
Input
The first line contains three space-separated integersN, Bytes,A, Bytes,B(1 digit ≤ DigitNLimit ≤ limit 105; 1 limit ≤ limitA, Bytes,BMemory ≤ memory 109). The next line containsNSpace-separated distinct integersP1, bytes,P2, middle..., middle ,...,PN(1 digit ≤ DigitPILimit ≤ limit 109 ).
Output
If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then printNIntegers:B1, bytes,B2, middle..., middle ,...,BN(BIEquals either 0, or 1), describing the division. IfBIEquals to 0, thenPIBelongs to setA, Otherwise it belongs to setB.
If it's impossible, print "NO" (without the quotes ).
Sample test (s) input
4 5 92 3 4 5
Output
YES0 0 1 1
Input
3 3 41 2 4
Output
NO
Note
It's OK if all the numbers are in the same set, and the other one is empty.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <set>#include <map>using namespace std;int n,a,b,id;int p[100100];set<int> st;map<int,int> mp;int fa[100100];int find(int x){if(x==fa[x]) return x;return fa[x]=find(fa[x]);}void Bing(int a,int b){int A=find(a),B=find(b);if(A==B) return ;fa[B]=A;}int main(){scanf("%d%d%d",&n,&a,&b);for(int i=1;i<=n;i++){scanf("%d",p+i);st.insert(p[i]);mp[p[i]]=++id;fa[i]=i;}fa[n+1]=n+1;///A fa[n+2]=n+2;///Bfor(int i=1;i<=n;i++){int x=p[i];if(st.count(a-x)){Bing(mp[x],mp[a-x]);}else{Bing(n+1,mp[x]);}if(st.count(b-x)){Bing(mp[x],mp[b-x]);}else{Bing(n+2,mp[x]);}}if(find(n+1)==find(n+2)){puts("NO");}else{puts("YES");for(int i=1;i<=n;i++){printf("%d ",find(i)==find(n+1));}putchar(10);}return 0;}
E. Hack it! Time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Little X has met the following problem recently.
Let's defineF(X) As the sum of digits in decimal representation of numberX(For example,F(1234) rows = Second 1 rows + second 2 rows + second 3 rows + second 4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C ++ code:
ans = solve(l, r) % a; if (ans <= 0) ans += a;
This code will fail only on the test with. You are given number
A, Help Little X to find a proper test for hack. Input
The first line contains a single integerA(1 digit ≤ DigitALimit ≤ limit 1018 ).
Output
Print two integers:L, Bytes,R(1 digit ≤ DigitLLimit ≤ limitRUnknown <limit 10200)-the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
Sample test (s) input
46
Output
1 10
Input
126444381000032
Output
2333333 2333333333333
__author__ = 'ckboss'm=int(input())x,t=10**100-1,m-100*45*10**99%mprint(t,t+x)