首页 技术 正文
技术 2022年11月15日
0 收藏 436 点赞 2,984 浏览 1346 个字

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 how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is 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 integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.

Output

Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to 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题意:给你你也序列,要你把它分成两份,使得两份序列的和相等,求有多少种分法....解题思路:       设序列的和为sum,分开后,打一个序列为sum1,第二个为sum2.  他们满足这么一个关系。   sum1+sum2=sum   则,sum1=sum2,可以表示为sum1=sum-sum1.

所以我们就可以先再输入的时候就算出sum,然后就只要循环算sum1,加判断是否相等就好了 代码如下:
 #include <stdio.h>
int a[];
int main()
{
int n;
while(scanf("%d",&n)==&&n){
long long sum1=,sum2=,sum=;
int t=;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
//printf("sum=%I64d\n",sum);
for(int i=;i<n-;i++){
sum1+=a[i];
//printf("sum1=%I64d sum2=%I64d\n",sum1,sum-sum1);
if(sum1==(sum-sum1)){
t++;
} } printf("%d\n",t);
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919