标签:
贪心找最优策略。大白上有详解。
不过这里有几个值得思考的地方。
还有几个地方想不明白,脑子不够用了,先记着,改天再做一遍
#include <cstdio> #include <algorithm> using namespace std; const int maxn = 100005; int n,a[maxn],left[maxn],right[maxn]; bool ok(int p) { int x = a[1],y = p-a[1]; left[1] = a[1];right[1] = 0; for(int i = 2;i<=n;++i) { if(i%2==0) { left[i] = min(a[i],x-left[i-1]); right[i] = a[i]-left[i]; } else { right[i] = min(a[i],y-right[i-1]); left[i] = a[i]-right[i]; } } return left[n]==0; } int main() { // freopen("in.txt","r",stdin); while(~scanf("%d",&n) && n) { for(int i = 1;i<=n;++i)scanf("%d",&a[i]); if(n==1){printf("%d\n",a[1]);continue;} int l = 0,r = 0; a[0] = a[n]; for(int i = 0;i<n;++i)l = max(l,a[i]+a[i+1]); if(n%2==1) { for(int i = 1;i<=n;++i)r = max(r,3*a[i]); while(l<r) { int m = (l+r)/2; if(ok(m))r = m; else l = m+1; } } printf("%d\n",l); } return 0; }
标签:
原文地址:http://www.cnblogs.com/GJKACAC/p/4239987.html