http://codeforces.com/contest/526/problem/E
题意:给一个环,每个点有权值,每次给一个数B,求把这个环切割成若干部分,每个部分不超过B,至少要切成几块?
#include<cstdio> #include<cmath> #include<iostream> #include<cstring> #include<algorithm> #define ll long long ll a[2000005]; int g[2000005],f[2000005]; int n,m; ll read(){ ll t=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();} return t*f; } int main(){ n=read();m=read(); for (int i=1;i<=n;i++) a[i]=read(),a[i+n]=a[i]; for (int i=1;i<=2*n;i++) a[i]+=a[i-1]; while (m--){ for (int i=1;i<=2*n;i++) g[i]=i,f[i]=0; ll T=read(); int j=1,ans=0x7fffffff; for (int i=n+1;i<=2*n;i++){ while (j<=i&&a[i]-a[j-1]>T) j++; f[i]=f[j-1]+1; g[i]=g[j-1]; if (i-g[i]>=n) ans=std::min(ans,f[i]); } printf("%d ",ans); } return 0; }