Codeforces 18C C. Stripe
Codeforces 18C C. Stripe
链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/E
题目:
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
题意:
求能将前面和后面分为和相等的两部分的次数
分析:
1.求前K个数的和b[k]和后n-k+1个数的和c[k+1]
2.比较大小,若相等记一次
代码:
#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=; int a[maxn],b[maxn],c[maxn]; //数组很大时要放在外面,不然会出现WA int main()
{
int n;
scanf("%d",&n);
b[]=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=b[i-]+a[i]; //求前i项的和
}
for(int j=n;j>=;j--)
{
c[j]=c[j+]+a[j]; //求后n-j+1项的和
}
int ans=;
for(int k=;k<n;k++)
{
if(b[k]==c[k+]) //比较
ans++;
}
printf("%d\n",ans);
return ;
}
读了好久的题目,一开始对负数那里不理解,仔细分析了一下,又听别人说了就理解了。
Codeforces 18C C. Stripe的更多相关文章
- CodeForces 219C Color Stripe
Color Stripe Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submi ...
- CodeForces 18C
Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...
- Codeforces 219C - Color Stripe - [DP]
题目链接:http://codeforces.com/problemset/problem/219/C 题意: 给你 $n$ 个方块排成水平一排,每个方块都涂上 $k$ 种颜色中的一种.要求对尽量少的 ...
- Codeforces 219C Color Stripe(思维+字符串)
题目链接:http://codeforces.com/problemset/problem/219/C 题目大意: 给出一个字符串,只包含k种字符,问最少修改多少个字符(不增长新的种类)能够得到一个新 ...
- CF--思维练习--CodeForces - 219C Color Stripe (思维)
ACM思维题训练集合 A colored stripe is represented by a horizontal row of n square cells, each cell is paine ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- Codeforces Beta Round #18 (Div. 2 Only) C. Stripe 前缀和
C. Stripe Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/18/C ...
- 贪心 Codeforces Round #135 (Div. 2) C. Color Stripe
题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #incl ...
- CodeForces 21C Stripe 2 构造题
题目链接: 题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #inclu ...
随机推荐
- latex如何把目录页的页码去掉?
页眉的显示与关闭,清空,还有样式之间的切换,需要用到如下几个命令: \pagestyle 用于设置当前页以及后续页面的页眉显示情况(可称为页版式).中间页版式可由\thispagestyle命令来指 ...
- 关于CSS动画几点要注意的地方
关于CSS动画几点要注意的地方 js操作transition无效果 先看这个demo以及stackoverflow的问题 http://jsfiddle.net/ThinkingStiff/QNnnQ ...
- Springmvc+Spring+Hibernate搭建方法及实例
Springmvc+Spring+Hibernate搭建方法及实例
- tpopela/vips_java
tpopela/vips_java Implementation of Vision Based Page Segmentation algorithm in Java
- Windows环境下用C#编程将文件上传至阿里云OSS笔记
Windows环境下用C#编程将文件上传至阿里云OSS笔记 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/detai ...
- Python输出中文乱码问题
//建立一个文件test.txt,文件格式用ANSI,内容为: //abc中文 //用python来读取 # coding=gbk print open("Test.txt").r ...
- BingMap的GeocodeService进行地理位置正向和反向检索--后台实现
一.加入GeocodeService的Web服务引用 地理编码服务(GeocodeService)是以WCF技术公布的一个Web服务,地图编码服务提供了以一个有效的物理地址在地图上匹配其相应的地图地址 ...
- [Codecademy] HTML&CSS 第三课:HTML Basic II
本文出自 http://blog.csdn.net/shuangde800 [Codecademy] HTML && CSS课程学习目录 --------------------- ...
- /etc/ld.so.conf详解
/etc/ld.so.conf 此文件记录了编译时使用的动态库的路径,也就是加载so库的路径. 默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件,而通常通过源码包进行安装 ...
- C#操作Office.word(一)
该文章主要是讲述如何使用VS2010创建word文档,因为在项目中我们可能需要点击一个按钮把数据库中的项目表单或图片显示到word文档中,因此该文章主要分析如何使用VS2010创建word文档并填写相 ...