Title: Hdoj 5037 Frog
Ask: Always clever frog, each can the length of L, Hecoin for M, drink center some land, it will choose to jump as few times as possible, now God can go to drink inside the land (as a point), let the frog jump the most times, the maximum number of times.
Analysis: 1: First of all, if you add a distance greater than (l+1), then God will give him the paragraph (l+1), because I give him (l+1), it can not jump past, the inevitable middle of a point, let the frog jump, so sure the number of steps maximum. (Greedy strategy)
2: Greedy time with each section of the remaining interval starting point as the starting point of greed, if it and the back interval and greater than or equal to (l+1), then you can let it skip the front interval, otherwise let continue to add.
It's been three hours since the game was played, in fact, the greedy strategy was right, at that time just retained the remainder, but did not count from the remainder of the first (that is, the interval initial point), after the WA after a few times, the generation of random numbers found to start from the interval initial point. Then think of how to deal with the back, when the writing is very complex, did not debug out.
In the middle deliberately for a period of time to determine whether the DP, negative DP, may be the previous character exhausted, this one is not allowed.
AC Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
typedef long LL;
using namespace std;
const int maxn=200005;
int A[MAXN];
int main ()
{
int T;
scanf ("%d", &t);
for (int cas=1;cas<=t;cas++)
{
int n,m,l;
scanf ("%d%d%d", &n,&m,&l);
for (int i=1;i<=n;i++)
scanf ("%d", &a[i]);
a[++n]=m;a[0]=0;
int ans=0,k=l;
Sort (a,a+n+1);
for (int i=1;i<=n;i++)
{
int x= (a[i]-a[i-1])% (l+1);
int y= (a[i]-a[i-1])/(l+1);
ans+=y*2;
if (k+x>=l+1)
k=x,ans++;
else
k=x+k;
}
printf ("Case #%d:%d\n", Cas,ans);
}
return 0;
}