【题解】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);
	}
}

【题解】hdu5037 Frog

上一篇:vsCode常用插件推荐


下一篇:RocketMQ-broker状态管理及数据统计