Codeforces 18c-stripe Problem Solving experience

Source: Internet
Author: User

Original question:

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 nspace-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

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

Analysis: Sweep from start to finish, each sweep an accumulation front so the sum of the items, and then judge twice times and is not equal to the total can be, the complexity of n

Code:
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespacestd;inta[100000+Ten];intt_left[100000+Ten];intsum;intMain () {intCNT =0; int*p =A; intN; CIN>>N;  for(inti =0; I < n; i++) {scanf ("%d", A +i); if(i = =0) T_left[i]=A[i]; T_left[i]= T_left[i-1] +A[i]; Sum+=A[i]; }     for(inti =0; I < n1; i++)    {        if(2* T_left[i] = =sum) CNT++ ; } cout<< CNT <<Endl; return 0;}

Codeforces 18c-stripe Problem Solving experience

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.