标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 158 Accepted Submission(s): 83
Mean:
略
analyse:
二分答案 + 贪心验证
Time complexity: O(n)
Source code:
/* * this code is made by crazyacking * Verdict: Accepted * Submission Date: 2015-05-30-22.26 * Time: 0MS * Memory: 137KB */ #include <queue> #include <cstdio> #include <set> #include <string> #include <stack> #include <cmath> #include <climits> #include <map> #include <cstdlib> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #define LL long long #define ULL unsigned long long using namespace std; const int MAXN=100010; int num[MAXN],n,T,tmp[MAXN]; inline bool check(int l){ for(int i=1;i<=n;i++) tmp[i]=num[i]; tmp[1]=num[1]-l; for(int i=2;i<=n;i++) if(num[i]+l<=tmp[i-1]) return false; else tmp[i]=max(num[i]-l,tmp[i-1]+1); return true; } int main() { scanf("%d",&T); for (int Rt=1;Rt<=T;Rt++) { scanf("%d",&n); cout<<"Case #"<<Rt<<‘:‘<<endl; for(int i=1;i<=n;i++) scanf("%d",&num[i]); int l=0,r=1000000,ans=0; while(l<=r){ int mid=(l+r)>>1; if(check(mid)){ ans=mid; r=mid-1; }else{ l=mid+1; } } cout<<ans<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/crazyacking/p/4541184.html