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", 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?
Input
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.
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.
題意:給你一個數 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.141592653using 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;}
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 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?
Input
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
Output a single integer — the number of moments of time from the segment [l, 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
題意:給你 N 個固定的區間,M 個可以滑動的區間 且滑動的長度 t 可為[L,R]中的任意值。問在[ L , R ] 中有多少個 t 可以使得“ 滑動區間與固定區間有交集(在一個點上相交也算)”
所以。。。。暴力即可。。
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <sstream>#include <vector>#include <ostream>#include <string>#include <cstdlib>#include <cmath>#define PI 3.141592653using 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;}
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 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?
Input
The first line contains a single integer n (1 ≤ n ≤ 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 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.
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
題意:從 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.141592653using 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,歡迎指出!