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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Android(java)学习笔记108:通过反射获取私有构造方法并且使用
反射获取私有构造方法并且使用: 1.获取字节码文件.class对象: Class c = Class.forName("cn.itcast_01.Person") ...
- MSSQL系统表常用操作
1:获取当前数据库中的所有用户表 select Name from sysobjects where xtype='u' and status>=0 2:获取某一个表的所有字段 select n ...
- MeasureSpec介绍
在自定义View和ViewGroup的时候,我们经常会遇到int型的MeasureSpec来表示一个组件的大小,这个变量里面不仅有组件的尺寸大小,还有大小的模式. 这个大小的模式,有点难以理解.在系统 ...
- The Story of self Parameter in Python, Demystified
转自:http://www.programiz.com/article/python-self-why If you have been programming in Python (in obj ...
- MSP430常见问题之IO端口类
Q1:请问430 的I/O 中断能不能可靠的响应60ns 的脉冲信号, 就是来了一个60ns 的脉冲,430 的中断会有丢失吗?A1:端口支持的最高8M的时钟,无法响应这么快的频率. Q2:430是3 ...
- Radware中APPDirector系列的Farm Table中的session mode参数说明
Session mode中共有5种会话保持方式:1.Regular,是普通的会话保持,形成的表项是:Client ip+Server ip的形式2.EntryPerSession(EPS),是端口与i ...
- server 2003上为单点登录sso配置映射
单点登录不是本人做的,代码需要调用类似 http://***.com/login.sso 的地址.要成功调用,需要在IIS设置.sso为后缀的映射项. Win7系统下一设置完,就能成功调用. 但是服务 ...
- .NE 学习概要
也是个人的学习计划,仅供参考:)
- form提交数据中文乱码问题总结
一:form在前台以post方式提交数据: 浏览器将数据(假设为“中国”)发送给服务器的时候,将数据变成0101的二进制数据(假设为98 99)时必然要查码表,浏览器以哪个码表打开网页,浏览器就以哪个 ...
- Entity Framework 6.1 学习系列1--概况、安装
原文:Entity Framework 6.1 学习系列1--概况.安装 Entity Framework:实体框架,看名字就知道是针对模型数据的.这是MS推出的一款ORM工具. 与NHibernat ...