Program e--Codeforces 18C

Source: Internet
Author: User

Description

Once 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 Strip E. These numbers is integer and do 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

Input
9
1 5-6 7 9-16 0-2 2
Output
3
Input
3
1 1 1
Output
0
Input
2
0 0
Output
1


The main topic: there is a sequence contains n number, divides it into the left and right parts, asked to make the left and right sides of the sum must be equal, to find the number of occurrences of this situation.

Analysis: The problem is very simple, it is simple to solve with violence. First, the sum of the sequence (denoted by sum), and the number of the left is expressed in Z,
If Z=SUM/2, increase the number of times by 1 (in CNT).

Note: Due to the large number of sequences, it is not appropriate to add Z after each time to determine whether it is equal to SUM/2, which takes a long time, just to determine the value of sum%2 is 1 or 0,
If it is 1, then sum is an odd number, the direct output 0, if it is 0, representing the sum of even, continue to accumulate and then judge.




The code is as follows:




#include<iostream>#include<cstdio>Constint MAXN=100005;UsingNamespace Std;IntMain(){int T, SumA[MAXN],flag, Zot;While(scanf("%d", &t)==1){Sum=0, Zot=0, flag=0;For(int I=0; I<t; I++){scanf("%d"A+i); Sum+=a[I];}If(Sum%2){Printf("0\ n");Break;}For(int I=0; I<t-1;i++) Span class= "Sh-cbracket" >{zot+=a[i; Span class= "Sh-keyword" >if (Zot==sum/< Span class= "Sh-number" >2) ++flag  printf (\n,flag);  return 0;< Span class= "Sh-cbracket" >               

Program e--Codeforces 18C

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.