There is a game called "I Wanna Be the Guy", consisting of n levels. 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 only p levels of the game. And Little Y can pass only q levels 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?
The first line contains a single integer n (1 ≤ n ≤ 100).
The next line contains an integer p (0 ≤ p ≤ n) at first, then follows p distinct integers a1, a2, ..., ap (1 ≤ ai ≤ n). 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 1 to n.
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
4 3 1 2 3 2 2 4
I become the guy.
4 3 1 2 3 2 2 3
Oh, my keyboard!
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;
}
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 time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). 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 time between c1 and d1, between c2 and d2, ..., between cq and dq (all borders inclusive). But if he gets up at time t, these segments will be shifted by t. They become [ci + t, di + t] (for all i).
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 time between l and r (both borders inclusive). 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, r] suit for that?
The first line contains four space-separated integers p, q, l, r (1 ≤ p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000).
Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000).
It's guaranteed that bi < ai + 1 and dj < cj + 1 for all valid i and j.
Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.
1 1 0 4 2 3 0 1
3
2 3 0 20 15 17 23 26 1 4 7 11 15 17
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;
///cross
int 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;
}
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of n integers: 1, 2, ..., n. In a single step, you can pick two of them, let's denote them a and b, erase them from the sequence, and append to the sequence either a + b, or a - b, or a × b.
After n - 1 steps there is only one number left. Can you make this number equal to 24?
The first line contains a single integer n (1 ≤ n ≤ 105).
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 following n - 1 lines print the required operations an operation per line. Each operation should be in form: "a op b = c". Where a and b are the numbers you've picked at this operation; op is either "+", or "-", or "*"; c is the result of corresponding operation. Note, that the absolute value of c mustn'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.
1
NO
8
YES 8 * 7 = 56 6 * 5 = 30 3 - 4 = -1 1 - 2 = -1 30 - -1 = 31 56 - 31 = 25 25 + -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;
}
Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:
- If number x belongs to set A, then number a - x must also belong to set A.
- If number x belongs to set B, then number b - x must also belong to set B.
Help Little X divide the numbers into two sets or determine that it's impossible.
The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The next line contains n space-separated distinct integersp1, p2, ..., pn (1 ≤ pi ≤ 109).
If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B.
If it's impossible, print "NO" (without the quotes).
4 5 9 2 3 4 5
YES 0 0 1 1
3 3 4 1 2 4
NO
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;///B
for(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;
}
Little X has met the following problem recently.
Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 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.
The first line contains a single integer a (1 ≤ a ≤ 1018).
Print two integers: l, r (1 ≤ l ≤ r < 10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
46
1 10
126444381000032
2333333 2333333333333
__author__ = 'ckboss'
m=int(input())
x,t=10**100-1,m-100*45*10**99%m
print(t,t+x)