对于每一个测试样例,输出两行:
第一行输出:"Case #i:"。i代表第 i 组测试数据。
第二行输出一个正整数,代表满足条件的最小代价。
思路见码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
using namespace std;
#define LL long long
const int maxn = 100000 + 100;
const int INF = 0x3f3f3f3f;
//freopen("input.txt", "r", stdin);
int A[maxn], B[maxn];
bool testok(int n, int k) {
B[0] = -1000005;
for(int i = 1; i <= n; i++) {
if(A[i] > B[i - 1]) {
B[i] = max(B[i - 1] + 1, A[i] - k);
}
else {
if(A[i] + k <= B[i - 1]) return false;
else B[i] = B[i - 1] + 1;
}
}
return true;
}
int main() {
int T, kase = 0; scanf("%d", &T);
while(T--) {
int n; scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &A[i]);
int le = 0, ri = 1000000;
while(le < ri) {
int mi = (le + ri) >> 1;
if(testok(n, mi)) ri = mi;
else le = mi + 1;
}
printf("Case #%d:\n", ++kase);
printf("%d\n", ri);
}
return 0;
}