标签:
bzoj水题O(n2)都能过。直接O(n)。
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-‘0‘,c=getchar();
return x;
}
const int nmax=25;
int a[nmax];
int main(){
int n=read(),sum=0;
rep(i,1,n) a[i]=read(),sum+=a[i];
if(sum%2) {
printf("0\n");return 0;
}
int cur=1,ans=0,tot=0;sum>>=1;
rep(i,1,n-1){
tot+=a[i];
while(tot>sum) tot-=a[cur++];
if(tot==sum) ans++;
}
printf("%d\n",ans*(ans-1)>>1);
return 0;
}
N<= 20
标签:
原文地址:http://www.cnblogs.com/fighting-to-the-end/p/5858137.html