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

题目大意:有一个序列包含n个数,将其分为左右两部分,问要使得左右两边数之和须相等,求出现这种情况的次数。

分析:这题要求很简单,用暴力求解在简单不过了。先求这个序列的总和(用sum表示),左边数之和用z表示,
如果z=sum/2,就将次数加1(用cnt表示). 注意:由于序列的个数较大,不宜每次将z累加之后再判断其是否等于sum/2,这样所花的时间很长;只需判断sum%2的值是1还是0,
如果是1,则sum为奇数,直接输出0,如果是0,代表sum为偶数,继续累加再判断。 代码如下:
#include <iostream>
#include <cstdio>
const int maxn=100005;
using namespace std;
int main()
{
int t,sum,a[maxn],flag,zot;
while(scanf("%d",&t)==1)
{
sum=0,zot=0,flag=0;
for(int i=0;i<t;i++)
{
scanf("%d",a+i);
sum+=a[i];
}
if(sum%2)
{
printf("0\n");
break;
}
for(int i=0;i<t-1;i++)
{
zot+=a[i];
if(zot==sum/2)
++flag;
}
printf("%d\n",flag);
}
return 0;
}
 

Program E-- 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. CodeForces 18C

    Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...

  3. [Benchmark] Codeflaws: A Programming Competition Benchmark for Evaluating Automated Program Repair Tools

    Basic Information Publication: ICSE'17 Authors: Shin Hwei Tan, Jooyong Yi, Yulis, Sergey Mechtaev, A ...

  4. Codeforces Round #443 (Div. 1) A. Short Program

    A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...

  5. Codeforces Round #879 (Div. 2) C. Short Program

    题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...

  6. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  7. Codeforces Round #443 (Div. 2) C. Short Program

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. Codeforces 879C/878A - Short Program

    传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...

  9. codeforces 284 D. Cow Program(记忆化搜索)

    题目链接:http://codeforces.com/contest/284/problem/D 题意:给出n个数,奇数次操作x,y都加上a[x],偶数次操作y加上a[x],x减去a[x],走出了范围 ...

  10. Codeforces 878A - Short Program(位运算)

    原题链接:http://codeforces.com/problemset/problem/878/A 题意:给出n个位运算操作, 化简这些操作, 使化简后的操作次数不多于5步. 思路:我们可以对二进 ...

随机推荐

  1. hdu 5713(状态压缩DP)

    要进行两次dp, 第一个,dp[i],1<=i<=(1<<n) 其中用i的二进制形式表示已选择的点. dp[i] 用来保存i中的点构成一个连通块,边集多少种可能. 转移方程: ...

  2. Mybatis关联查询,查询出的记录数量与数据库直接查询不一致,如何解决?

    <select id="findUserInfoListForMap"    resultMap="BaseResultMap">  SELECT  ...

  3. mybatis <sql /> 配置中 返回值 resultType 与resultMap的区别

    mybatis的objectMapper.xml中, 1) 若<sql /> 查询语句中配置的是resultType=“实体类/DTO” ,则从mybatis返回的键值对结果集(Map)会 ...

  4. python剑指网络篇一

    #coding:utf-8 __author__ = 'similarface' #!/usr/bin/env python import socket #二进制和ASCII互转及其它进制转换 fro ...

  5. Python开发者须知 —— Bottle框架常见的几个坑

    Bottle是一个小巧实用的python框架,整个框架只有一个几十K的文件,但却包含了路径映射.模板.简单的数据库访问等web框架组件,而且语法简单,部署方便,很受python开发者的青睐.Pytho ...

  6. Nodejs环境变量

    PATH,就是那个意思,没有特殊含义. NODE_PATH,将node_modules作为全局模块,多个安装目录用;分开.这样node在加载模块时首先会到项目目录下的node_modules目录加载相 ...

  7. 5.3.1 新建Java工程和类

    1.新建工程 (1)打开Eclipse,选择工作区域 (2)选择“File”->“New”->“Java Project”命令,新建工程. (3)在弹出的新建工程对话框中,输入Projec ...

  8. Java基础:多线程

    基本概念 程序&线程&进程 程序是一个段可以提供业务功能的代码,它可以包含1个或多个进程.程序在OS上运行时表现为进程对各种资源(CPU,内存,Disk..)的消耗和处理. 进程是OS ...

  9. (04)odoo视图操作

    -----------------更新时间19:04 2016-09-29 星期四11:17 2016-09-18 星期日18:13 2016-04-05 星期二15:05 2016-03-14 星期 ...

  10. python中2进制、10进制、16进制等之间的转换

    10转2: bin(8) # '0b1000' 2转10: int( 10转16: hex(15) # '0xf' 16转10: int( 2进制和16进制中间通过转10进制可以相互转换 from b ...