博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
左右相等
阅读量:5744 次
发布时间:2019-06-18

本文共 1761 字,大约阅读时间需要 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 #include
2 using namespace std; 3 #define maxn 100000+5 4 int n, ans,flag; 5 int sum,lsum, rsum; 6 int arr[maxn]; 7 int judge(int m) 8 { 9 lsum = 0, rsum = 0;10 for (int i = 0; i
> n;34 for (int i = 0; i < n; i++)35 {36 cin >> arr[i];37 sum += arr[i];38 }39 if (sum % 2 != 0)40 flag = 0; //总和为奇数,直接判断不可以分成相等的两半41 else42 judge(n);43 if (flag == 1)44 cout <
<< endl;45 else46 cout << "0" << endl;47 48 return 0;49 }

 

 

转载于:https://www.cnblogs.com/Lynn0814/p/4711859.html

你可能感兴趣的文章
CSS中 Zoom属性 介绍
查看>>
java war maven 混淆 css/js class 加密
查看>>
Nginx + Spring Boot + jetty 大文件上传失败
查看>>
Spring MVC 测试样例
查看>>
关于页面中 JS 中windown.open( )方法打开新页面有可能会被浏览器拦截的问题
查看>>
基于定时器的动画和性能调优
查看>>
yii CLinkPager 分页控件
查看>>
github生成SSH公钥
查看>>
利用堆栈进行表达式求值的方法(二)
查看>>
IOS时间处理
查看>>
随手翻译ECMA5(一)
查看>>
mysql_list_tables方法已经过时的解决途径
查看>>
DevExpress GridView 那些事儿
查看>>
虚拟机Linux网络配置
查看>>
BYD S6
查看>>
什么是工程师文化?
查看>>
[cocos2dx-3.0] tinyxml2 loadFile真机下失败问题
查看>>
字符串反转实现
查看>>
Python中re(正则表达式)模块详解
查看>>
nginx防盗链设置
查看>>