Frog
Time Limit: 3000/1500 MS (Java/others) memory limit: 262144/262144 K (Java/Others)
Total submission (s): 634 accepted submission (s): 152
Problem descriptiononce upon a time, there is a little frog called Matt. One day, he came to a river.
The river cocould be considered as an axis. matt is standing on the Left Bank now (at position 0 ). he wants to cross the river, reach the right bank (at position m ). but Matt cocould only jump for at most l units, for example from 0 to L.
As the god of nature, you must save this poor frog. there are n rocks lying in the river initially. the size of the rock is negligible. so it can be indicated by a point in the axis. matt can jump to or from a rock as well as the bank.
You don't want to make the things that easy. so you will put some new rocks into the river such that Matt cocould jump over the river in maximal steps. and you don't care about the number of rocks you add since you are the God.
Note that Matt is so clever that he always choose the optimal way after you put down all the rocks.
Inputthe first line contains only one integer T, which indicates the number of test cases.
For each test case, the first line contains N, M, L (0 <= n <= 2*10 ^ 5, 1 <= m <= 10 ^ 9, 1 <= L <= 10 ^ 9 ).
And in the following n lines, each line contains one integer within (0, m) indicating the position of rock.
Outputfor each test case, just output one line "case # X: Y", where X is the case number (starting from 1) and Y is the maximal number of steps Matt shoshould jump.
Sample Input
21 10 552 10 336
Sample output
Case #1: 2Case #2: 4
Source2014 ACM/ICPC Asia Regional Beijing online
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n,m,l;int stone[200200];int main(){ int T_T,cas=1; scanf("%d",&T_T); while(T_T--) { scanf("%d%d%d",&n,&m,&l); for(int i=1;i<=n;i++) { scanf("%d",stone+i); } n++; stone[0]=0; stone[n]=m; n++; sort(stone,stone+n); int k=l,ans=0; for(int i=1;i<n;i++) { int x=(stone[i]-stone[i-1])%(l+1); int y=(stone[i]-stone[i-1])/(l+1); if(k+x>=l+1) { k=x; ans+=y*2+1; } else { k=x+k; ans+=y*2; } } printf("Case #%d: %d\n",cas++,ans); } return 0;}
Hdoj 5037 frog