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