首页 > 代码库 > Codeforces Round #268 (Div. 2) 题解
Codeforces Round #268 (Div. 2) 题解
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.
题意:给你一个数 N 意味着有 1 至 N 个关卡,然后 每行第一个数 p 代表后面有 p 个整数跟随。 每个整数代表 其 能过的关卡的编号。
而现在有两组编号,题目就是要求我们把两组编号合起来,看里面是否能有 1 至 N 所有的数。
如果有,则输出“I become the guy.” 否则输出Oh, my keyboard!
懂题意后这题就简单了,水掉就是!
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <vector> #include <ostream> #include <string> #include <cstdlib> #include <cmath> #define PI 3.141592653 using namespace std; int n; int p,q; int a[1000]; //用以标记 int main( ) { cin>>n; for(int i = 0;i <= n; i++) { a[i]=1; //初始化 } cin>>p; int x; while(p--) { scanf("%d",&x); a[x]=0; } cin>>q; while(q--) { scanf("%d",&x); a[x]=0; } int judge=0; for(int i = 1;i <= n; ++i) { judge=judge+a[i]; } if(judge) cout<<"Oh, my keyboard!"<<endl; else cout<<"I become the guy."<<endl; 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 <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <vector> #include <ostream> #include <string> #include <cstdlib> #include <cmath> #define PI 3.141592653 using namespace std; int p,q,l,r; int vis[55][2]; int main( ) { cin>>p>>q>>l>>r; int a,b; int kis[1100]; memset(kis,0,sizeof(kis)); for(int i = 0;i < p; i++) { scanf("%d%d",&a,&b); vis[i][0]=a; vis[i][1]=b; } int judge=0; while(q--) { scanf("%d%d",&a,&b); for(int i = l;i <= r; i++) { if(kis[i]==0) for(int j = 0;j < p; j++) { if(a+i==vis[j][1]||a+i==vis[j][0]||b+i==vis[j][1]||b+i==vis[j][0]) { kis[i]=1; break; } else if(b+i>vis[j][1]&&a+i<vis[j][1]) { kis[i]=1; break; } else if(b+i>vis[j][0]&&a+i<vis[j][0]) { kis[i]=1; break; } else if(b+i<vis[j][1]&&a+i>vis[j][0]) { kis[i]=1; break; } } } } for(int i = l; i <= r; i++) { judge+=kis[i]; } cout<<judge<<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
题意:从 1 至 N 个数取两个数,用“ + ”,“ - ”,“ * ”进行运算,并把得到的结果加到原来的数中。如此进行N-1次操作,凑出24即可。
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <vector> #include <ostream> #include <string> #include <cstdlib> #include <cmath> #define PI 3.141592653 using namespace std; int n; int main( ) { cin>>n; if(n<4) { cout<<"NO"<<endl; } else { cout<<"YES"<<endl; if(n%2==0) { printf("2 * 3 = 6\n"); printf("6 * 4 = 24\n"); printf("1 * 24 = 24\n"); for(int i = 5;i < n; i+=2) { printf("%d - %d = 1\n",i+1,i); printf("1 * 24 = 24\n"); } } else { printf("4 * 5 = 20\n"); printf("3 + 20 = 23\n"); printf("23 + 2 = 25\n"); printf("25 - 1 = 24\n"); for(int i = 6; i< n; i+=2) { printf("%d - %d = 1\n",i+1,i); printf("1 * 24 = 24\n"); } } } return 0; }
如有BUG,欢迎指出!
Codeforces Round #268 (Div. 2) 题解