标签:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
int nums[100010], numsc[100010];
int main() {
int T;
cin >> T;
for(int nq = 0; nq != T; ++nq) {
printf("Case #%d:\n", nq+1);
cin >> n;
for(int i = 0; i != n; ++i) {
// cin >> nums[i];
scanf("%d", &nums[i]);
}
int beginK = -1, endK = 5000000, midK;
bool can;
while(endK - beginK > 1) {
midK = (beginK + endK) / 2;
for(int i = 0; i != n; ++i) {
numsc[i] = nums[i];
}
numsc[0] -= midK;
can = true;//当前K可行
for(int i = 1; i != n; ++i) {
if(numsc[i] > numsc[i-1]) {
if(numsc[i] - numsc[i-1] > midK) {
numsc[i] -= midK;
}
else {
numsc[i] = numsc[i-1] + 1;
}
}
else if(midK < numsc[i-1] - numsc[i] + 1) {
beginK = midK;
can = false;//当前K不可行
break;
}else {
numsc[i] = numsc[i-1] + 1;
}
}
if(can) endK = midK;
}
cout << endK << endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4541882.html