博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2015 HUAS Summer Contest#3~E
阅读量:5257 次
发布时间:2019-06-14

本文共 1581 字,大约阅读时间需要 5 分钟。

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 解题思路:这个题目的意思就是求一组数前后两端的和一样的情况有多少种,这里要注意的是它只能分成两个部分。看懂题目很重要,其实首先我就看错题了,我以为是求当两端相等时是 在第几个数的后面,这是很容易出错的。解题步骤很简单,就是先将这组数的和求出来,然后从左网友一一遍历,遇到前面的和等于总和减去前面的和的就将要输出的数加1,但在开始前要 讲要输出的数记为0.这里还要注意的一点是遍历只能到n-1,是不能够遍历到最后一个数的。
程序代码:
#include
#include
using namespace std; const int m=100010; int a[m]; int c,sum; int main() { int n,i; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } int floag=0; for(i=1;i

转载于:https://www.cnblogs.com/chenchunhui/p/4713241.html

你可能感兴趣的文章
笔记本设置无线热点
查看>>
awk算术运算一例:统计hdfs上某段时间内的文件大小
查看>>
h.264 Mode Decision
查看>>
面向对象进阶(反射)
查看>>
《基于B/S中小型超市进销存管理系统的研究与设计》论文笔记(十六)
查看>>
200佳优秀的国外创意设计网站推荐【全集】 转
查看>>
0082-莱布尼兹三角形
查看>>
HDU2489【状压枚举】
查看>>
Android:SQLite数据绑定ListView
查看>>
Lucene.net(4.8.0) 学习问题记录五: JIEba分词和Lucene的结合,以及对分词器的思考
查看>>
LeetCode 104. Maximum Depth of Binary Tree
查看>>
Android广播学习笔记
查看>>
C# 多线程
查看>>
UVA12108
查看>>
HTML5模仿刮奖效果-页面涂抹消失插件wScratch
查看>>
SpringBoot 之Spring Boot Starter依赖包及作用
查看>>
jQuery事件
查看>>
Android 分享之butterknife绑定失效
查看>>
堆排序-heapsort
查看>>
使用Node.js+Hexo+Github搭建个人博客(续)
查看>>