标签:des style blog http color io os ar for
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #include<string> 12 #define inf 1000000000 13 #define maxn 101000 14 #define maxm 500+100 15 #define eps 1e-10 16 #define ll long long 17 #define pa pair<int,int> 18 #define for0(i,n) for(int i=0;i<=(n);i++) 19 #define for1(i,n) for(int i=1;i<=(n);i++) 20 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 21 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 22 #define mod 1000000007 23 using namespace std; 24 inline int read() 25 { 26 int x=0,f=1;char ch=getchar(); 27 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 28 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();} 29 return x*f; 30 } 31 int n,s[maxn],q[maxn],wide[maxn],h[maxn]; 32 int main() 33 { 34 freopen("input.txt","r",stdin); 35 freopen("output.txt","w",stdout); 36 n=read(); 37 for1(i,n)s[i]=s[i-1]+read(); 38 int l=0,r=0;q[0]=n+1; 39 for3(i,n,1) 40 { 41 while(l<r&&wide[q[l+1]]<=s[q[l+1]-1]-s[i-1])l++; 42 wide[i]=s[q[l]-1]-s[i-1]; 43 h[i]=h[q[l]]+1; 44 while(l<r&&wide[i]-s[i-1]<wide[q[r]]-s[q[r]-1])r--; 45 q[++r]=i; 46 } 47 printf("%d\n",h[1]); 48 return 0; 49 }
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int a[100010],d[100010],s[100010],f[100010],q[100010],n,i,j,l,r; 5 int main() 6 { 7 cin>>n; 8 for(i=n;i;i--) scanf("%d",&a[i]); 9 for(i=1;i<=n;i++) s[i]=s[i-1]+a[i]; 10 l=1; 11 for(i=1,j=0;i<=n;i++) 12 { 13 while(l<=r&&s[i]-s[q[l]]>=f[q[l]]) j=q[l++]; 14 f[i]=s[i]-s[j]; 15 d[i]=d[j]+1; 16 while(l<=r&&f[i]<=f[q[r]]-s[i]+s[q[r]]) r--; 17 q[++r]=i; 18 } 19 cout<<d[n]<<endl; 20 return 0; 21 }
BZOJ1233: [Usaco2009Open]干草堆tower
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/zyfzyf/p/4049991.html