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. 使用dispatch_group实现并封装分组并发网络请求

    在实际开发中我们通常会遇到这样一种需求:某个页面加载时通过网络请求获得相应的数据,再做某些操作.有时候加载的内容需要通过好几个请求的数据组合而成,比如有两个请求A和B,我们通常为了省事,会将B请求放在 ...

  2. 插入到Mysql数据库中的汉字乱码

    出现这个问题,大都是在Mysql安装的时候没有选择成UTF8,默认安装的话应该是latin编码 安装完成之后后期可以在配置文件中修改. 打开Mysq的安装位置,查看my.ini文件. 修改如下设置编码 ...

  3. [设计模式]<<设计模式之禅>>关于迪米特法则

    迪米特法则(Law of Demeter,LoD)也称为最少知识原则(Least KnowledgePrinciple,LKP),虽然名字不同,但描述的是同一个规则:一个对象应该对其他对象有最少的了解 ...

  4. CSS3如何实现2D转换和3D转换,他们有何区别

    CSS3中2D3D技术的发展,带来了更丰富的视觉效果~他们的实现机理是怎样的呢? 1定义 2D: 能够对元素进行移动,缩放,转动,拉长或拉伸. 3D: 允许对元素进行格式化,在三维空间进行操作.元素改 ...

  5. FindControl 无法找到控件问题解决方案

    若用 string cdept =((HtmlInputText)FindControl("dept0" + i.ToString())).Value; 提示结果为空值,即无法找到 ...

  6. Android--仿QQ侧滑菜单

    首先还是先看一下效果图吧,这个示例在网上能找到很多,我主要在此是做一个小结和一些代码的分析,当是自己在学习过程中的一个积累,因为网上同样的文章很多,所以也无法探究最初的来源是哪里了. 我们可以从效果图 ...

  7. .Net 微信开发与微信支付

    .NET     https://github.com/JeffreySu/WeiXinMPSDK JAVA   http://git.oschina.net/pyinjava/fastweixin ...

  8. 合理使用mysql中的load data infile导入数据

    基本语法: load data  [low_priority] [local] infile 'file_name txt' [replace | ignore]into table tbl_name ...

  9. c# DateTime时间格式和JAVA时间戳格式相互转换

    /// java时间戳格式时间戳转为C#格式时间 public static DateTime GetTime(long timeStamp) { DateTime dtStart = TimeZon ...

  10. lex&yacc4

    yacc: we cannt use the $$ value dirictly. we need get it irrotly;