A. Gabriel and Caterpillar
Test instructions: That is, a child to observe the caterpillar from the H1 to the place of the H2, the caterpillar climbed from 10 to 22, the distance to climb every hour is a, night 22 o'clock to the next morning 10 point caterpillar rest every hour drop B distance, but the initial state is that the child from 14 o'clock to observe the caterpillar, It's going to be a day after 24.
Idea: Simulation, but the details of the place to pay attention to
Hint: But you need to know what the situation will never climb up, that is, the drop per hour is higher than the distance per hour, but there is a detail, even if b>a but the caterpillar can climb 10 hours, if in this 10 hours climbed to the H2 that is in time b>a it can also climb to
1#include <iostream>2#include <cstdio>3#include <cmath>4 intMain ()5 {6 intn,m;7 intb;8 while(~SCANF ("%d%d%d%d",&n,&m,&a,&b)) {9 intans=m-N;Ten intflag=1;//tag variables, record whether you can crawl to the end One intDistance=0; A intTime=0; -distance+=a*8; - if(distance<ans) { the while(1){ -distance-=b* A;//Rest -++time;//break time is over 24, so count one day . -distance+=a* A; + if(Distance>=ans) Break; - if(b>=a) {//judge directly in the loop, because 10 hours before you can climb to the end. +flag=0;//It wouldn't be in the loop. A Break; at } - } - } - if(!flag) printf ("-1\n"); - Elseprintf"%d\n", time); - } in}
B. Z-sort
Test instructions: First give you a series, ask whether the number of numbers can be formed a for each even term in the sequence exists ai ≥ ai -1 , for each odd item there is ai ≤ ai -1 idea: I think so, Since there are two conditions to satisfy, it is a non-decrement for the odd term from the front to the back, which is a non-increment for the even term before and after.
Then for the given sequence, a sequence, and then greedy, specific to see the code bar
1#include <cmath>2#include <cstring>3#include <iostream>4#include <cstdio>5#include <algorithm>6 using namespacestd;7 intnum[1005];8 intMain ()9 {Ten intN;SCANF ("%d",&n); One for(intI=1; i<=n;++i) Ascanf"%d",&num[i]); -Sort (num+1, num+n+1); - intans[1005]; the intAdd,dre; -Add=1; -Dre=N; - for(intI=1; i<=n;++i)//construct such a sequence + if(i%2==0) -ans[i]=num[dre--]; + Else Aans[i]=num[add++]; at intflag=1; - //for (int i=1;i<=n;++i) - //printf ("%d", ans[i]); - //printf ("\ n"); - for(intI=2; i<=n;++i)//Judging whether the sequence of constructs satisfies the condition - if(i%2==0){ in if(ans[i]<ans[i-1]) flag=0; - } to Else + if(ans[i]>ans[i-1]) flag=0; - if(!flag) printf ("Impossible"); the Else for(intI=1; i<=n;++i) printf ("%d", Ans[i]); *printf"\ n"); $ return 0;Panax Notoginseng}
C D Test instructions actually understand, is to do not come out of the aerobic Ah,
Reading the question is better than before,
Keep working on it,
Educational codeforces Round A b question,