codeforce 469 B C -模拟 -构造

标题 ## B. Chat Online 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?
【codeforce 469 B C -模拟 -构造】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? It’s guaranteed that bi? Output
Output a single integer — the number of moments of time from the segment [l,?r] which suit for online conversation.
Examples
inputCopy
1 1 0 4
2 3
0 1
outputCopy
3
inputCopy
2 3 0 20
15 17
23 26= v你吗
1 4
7 11
15 17
outputCopy
20
MEAN:
a和b聊天 ,每个人都有在线时间区间 ,b早起会迟到,相应时间向后推移 问有多少时间他们能再一起聊天
输入 p,q,l,r p个a 时间段,q个b 时间段 ,l-r b可能早起时间 ;
CODE
#include using namespace std; int main() { int p,q,l,r,i,j; while(cin>>p>>q>>l>>r) { int stu[2222]= {0}; for(i=0; iint a,b; scanf("%d%d",&a,&b); for(j=a; j<=b; j++) { stu[j]=1; } } vector vec; vec.clear(); for(i=0; i1000) break; if(stu[j+vec[i]]) { ans++; break; } } } cout<

C. 24 Game

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.
Examples
inputCopy
1
outputCopy
NO
inputCopy
8
outputCopy
YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -1
1 - 2 = -1
30 - -1 = 31
56 - 31 = 25
25 + -1 = 24
MEAN :
输入 一个n 你可以使用1-n的数字 把这些书推入队列 ,任取两个数可以进行 + - * 操作 得到新的数推入队列,问能否凑成24
#include using namespace std; int main() { int n,i,j; while(cin>>n) { if(n<4) { puts("NO"); } else { puts("YES"); if(!(n%2)) { for(i=n; i>=5; i--) { printf("%d - %d = 1\n",i,i-1); printf("1 * 1 = 1\n"); i--; }puts("1 * 2 = 2"); puts("2 * 3 = 6"); puts("4 * 6 = 24"); } else { for(i=n; i>5; i--) { printf("%d - %d = 1\n",i,i-1); printf("1 * 1 = 1\n"); i--; } puts("3 * 5 = 15"); puts("2 * 4 = 8"); puts("1 + 8 = 9"); puts("9 + 15 = 24"); }} } }

    推荐阅读