Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrotean integer number, possibly negative. He became interested in how many waysexist to cut this stripe into two pieces so that the sum of numbers from onepiece is equal to the sum of numbers from the other piece, and each piececontains positive integer amount of squares. Would you help Bob solve thisproblem?
Input
The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in thestripe. The second line contains n space-separated numbers — they arethe numbers written in the squares of the stripe. These numbers are integer anddo not exceed 10000 in absolute value.
Output
Output the amount of ways to cut the stripe into two non-empty pieces sothat the sum of numbers from one piece is equal to the sum of numbers from theother piece. Don't forget that it's allowed to cut the stripe along thesquares' borders only.
Sample test(s)
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
思路:
题目要求前K项和与后N-K项和相等的个数,直接干
程序:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;
#define L(u) (u<<1)
#define R(u) (u<<1|1)
#define lowbit(x) (x&-x)
#define rep(i,x,y) for (i=x;i<=y;i++)
#define ll __int64
#define max(x,y) ((x>y)?(x),(y))
#define min(x,y) ((x<y)?(x),(y))
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define slld(x) scanf("%lld",&x)
const int N = 100005;
struct node
{
int x, y;
};
bool cmp(node a, node b)
{
return a.x<b.x;
}
int a[N], sum[N];
int main()
{
int n;
int i;
sd(n);
memset(sum, 0, sizeof(sum));
rep(i, 1, n)
{
sd(a[i]);
sum[i] = sum[i - 1] + a[i];
}
int count = 0;
rep(i, 1, n - 1)
{
if (sum[i] == sum[n] - sum[i])
{
count++;
}
}
printf("%d\n", count);
return 0;
}