CodeForces 18C
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
9
1 5 -6 7 9 -16 0 -2 2
3
3
1 1 1
0
2
0 0
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的更多相关文章
- Codeforces 18C C. Stripe
Codeforces 18C C. Stripe 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/E 题 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- .NET自动识别HttpWebResponse的编码及是否压缩
请求和响应头 POST的数据 最近项目使用HttpWebRequest请求网页,处理HttpWebResponse返回消息体,发现网页可能是有GZIP压缩等,所得数据乱码,所以相处了解决方案,大家共同 ...
- warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
bug来源: 一直在看sift然后就手贱的给 opencv源码做注释,如果在vs里面打开会一直相安无事,但是问题出在我用了notepad++. 这样就报了标题的错误. 因为notepad++会以uni ...
- SSH整合_struts.xml 模板
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...
- 【LIC】O(nlogn)解法
[LIC--最长递增子序列问题] 在一列数中寻找一些数,这些数满足:任意两个数a[i]和a[j],若i<j,必有a[i]<a[j],这样最长的子序列称为最长递增子序列. O(nlogn)算 ...
- poj 1201 差分约束
http://www.cnblogs.com/wangfang20/p/3196858.html 题意: 求集合Z中至少要包含多少个元素才能是每个区间[ai,bi]中的元素与Z中的元素重合个数为ci. ...
- JavaScript常用的经典小技巧
1.屏蔽鼠标右键 <--body 方式--> <body oncontextmenu="window.event.returnValue=false"> & ...
- MongoDB - Installing MongoDB on Windows
1. 在 http://www.mongodb.org/downloads 选择下载所需的版本. 2. 执行 msi 安装包,可通过 Custom 选项,选择安装目录. 3. 创建数据目录.Mongo ...
- HTTP - 条件请求
当 HTTP 请求包含 If-XXX 这种样式的首部时,服务器会对附带的条件进行判断,只有判断指定条件为真,才会执行请求.这样的请求首部有五个,分别是 If-Modified-Since.If-Unm ...
- IIS服务器应用程序不可用的解决办法
转载:http://www.cnblogs.com/caicainiao/archive/2010/11/29/1891085.html 这个问题见了好几次,在.net下 Microsoft visu ...
- 使用iTextSharp来填充PDF模板文件
需求简介: 遇到了这样一个需求:某公司需要为所有用户的培训生成一个培训记录,过程如下: (1)用户在培训完之后会进入到一个填写信息的界面. (2)用户填写信息. (3) ...