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);
}
}

CodeForces 18C的更多相关文章

  1. Codeforces 18C C. Stripe

    Codeforces 18C  C. Stripe 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/E 题 ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. 贴心小技能——纯CSS实现的帮助提示

    1. 新技能传授---哒哒哒哒 我们经常会接到这样的小需求,鼠标放在某个位置实现一段小提示. 你还在用js实现这样一个小功能,你就太out了,来看看我们用纯CSS打造的帮助提示. 2. html &l ...

  2. SQL_server 数据库备份信息查看

    select distinct s.database_name, s.first_lsn,s.last_lsn,s.database_backup_lsn,s.backup_finish_date,s ...

  3. 关于win7系统中所有exe文件都被以word方式打开的解决方法

    手残一刻,电脑桌面所有的软件快捷方式都变成了word的打开方式,鼠标右键选中某exe文件也没打开方式那个选项, 第一次尝试: 在控制面板——默认程序中修改默认打开方式,但是没有找到解决方法

  4. [改善Java代码]警惕泛型是不能协变和逆变的

    什么叫做协变(covariance)和逆变(contravariance)? 在变成语言的类型框架中,协变和逆变是指宽类型和窄类型在某种情况下(如参数,泛型,返回值)替换或交换的特性,简单的说,协变是 ...

  5. 直接查数据导出xls

    直接查数据导出xls/usr/bin/mysql --default-character-set=utf8 -uroot -p"123456" -e"select * f ...

  6. [Wordpress]Wordpress使用SMTP发送电邮

    参考:phpmailer_init中的代码,可以配置使用SMTP发送电邮 官方的案例代码是: add_action( 'phpmailer_init', 'my_phpmailer_example' ...

  7. 踩到两只“bug”

    近期在修复ex和头儿的代码时,碰到两个特别点的bug,其实也不能称之为bug,非常简单的用法,稍不严谨点可能就出错了. 第一个是in_array,大家都知道功能是检查一个值是否在数组中,第三个参数传入 ...

  8. jquery 60秒倒计时(方法二)

    <script type="text/javascript">var wait=60;document.getElementById("btn"). ...

  9. AppScan安全问题解决方案

    一. 环境准备 测试通常给的是PDF文档,动辄几百页,看起来很费劲,看文档的时间可能比解决问题的时间还长...所以作为需要解决问题的我们来说,最好安装AppScan,请测试人员提供类型为AppScan ...

  10. iOS 之美:iOS Delegate 使用五步曲

    在iOS 开发中, 搞清楚Delegate 是需要花些时间的. Delegate 本来是软件架构设计的一种理念.对于像手机这样一个有限的设备,我们需要充分考虑到:内存要尽量省着用: 视图之间的关系要清 ...