Codeforces Beta Round #18 (Div. 2 only) C. Stripe prefix and

Source: Internet
Author: User

C. Stripe

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/problemset/problem/18/C

Descriptiononce Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in what many ways exist to cut this stripe into II pieces so and the sum of numbers from one piece I s equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?

Input

The first input line contains an integer n (1≤n≤105)-amount of squares in the stripe. The second line contains n space-separated numbers-they is the numbers written in the squares of the stripe. These numbers is integer and does not exceed 10000 in absolute value.

Output

Output The amount of ways to cut the stripe into and non-empty pieces so, the sum of numbers from one piece is equal t o 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

HINT

Test instructions

Give you the number of N, and then say with a pair of scissors to cut this sequence, ask the left equals to the right, ask how many kinds of cut-off method

Exercises

Statistics a prefix and just fine ...

Code

//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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 2000001#defineMoD 1000000007#defineEPS 1e-9intNum;Charch[ -];Const intinf=0x3f3f3f3f; inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************intN;intA[MAXN];intSUM[MAXN];intMain () {intn=read ();  for(intI=1; i<=n;i++) A[i]=read (), sum[i]=a[i]+sum[i-1]; intans=0;  for(intI=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 prefix and

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.