CodeForces 18C - Stripe

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;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值