【题解】hdu5037 Frog

awsl

#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 200005;
int T, N, M, K, A[MAXN];
int main()
{
	scanf("%d", &T);
	for (int cas=1; cas<=T; cas++) {
		scanf("%d%d%d", &N, &M, &K);
		for (int i=1; i<=N; i++) scanf("%d", &A[i]); A[N+1] = M;
		sort(A+1, A+N+1);
		int pre = K, ans = 0;
		for (int i=0; i<=N; i++) {
			int a = (A[i+1]-A[i]) / (K+1);
			int b = (A[i+1]-A[i]) % (K+1);
			if (pre+b> K) { pre = b, ans += a*2+1; }
			else { pre += b; ans += a*2; }
		}
		printf("Case #%d: %d\n", cas, ans);
	}
}
上一篇:OracleSpatial函数实例


下一篇:CF1601 B. Frog Traveler