标签:
Time Limit: 20 Sec
Memory Limit: 256 MB
http://codeforces.com/problemset/problem/18/C
Input
The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don‘t forget that it‘s allowed to cut the stripe along the squares‘ borders only.
Sample Input
9
1 5 -6 7 9 -16 0 -2 2
Sample Output
3
题意
给你n个数,然后说用一个剪刀把这个序列剪开,要求左边等于右边,问总共有多少种剪开的方法
题解:
统计一个前缀和就好了……
代码
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 2000001 #define mod 1000000007 #define eps 1e-9 int Num; char CH[20]; const int inf=0x3f3f3f3f; inline ll read() { int x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //************************************************************************************** int n; int a[maxn]; int sum[maxn]; int main() { int n=read(); for(int i=1;i<=n;i++) a[i]=read(),sum[i]=a[i]+sum[i-1]; int ans=0; for(int i=1;i<=n-1;i++) { if(sum[i]==sum[n]-sum[i]) ans++; } cout<<ans<<endl; }
Codeforces Beta Round #18 (Div. 2 Only) C. Stripe 前缀和
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4601552.html