博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Beta Round #18 (Div. 2 Only) C. Stripe 前缀和
阅读量:7026 次
发布时间:2019-06-28

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

C. Stripe

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/problemset/problem/18/C

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

Sample Output

3

HINT

 

题意

给你n个数,然后说用一个剪刀把这个序列剪开,要求左边等于右边,问总共有多少种剪开的方法

题解:

统计一个前缀和就好了……

代码

 

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 2000001#define mod 1000000007#define eps 1e-9int Num;char CH[20];const int inf=0x3f3f3f3f;inline ll read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//**************************************************************************************int n;int a[maxn];int sum[maxn];int main(){ int n=read(); for(int i=1;i<=n;i++) a[i]=read(),sum[i]=a[i]+sum[i-1]; int ans=0; for(int i=1;i<=n-1;i++) { if(sum[i]==sum[n]-sum[i]) ans++; } cout<
<

 

转载地址:http://tjoxl.baihongyu.com/

你可能感兴趣的文章
总结一些机器视觉库
查看>>
在CentOS Linux下部署Activemq 5
查看>>
把mysql脚本或其他数据库脚本导入Powerdesigner
查看>>
phalcon 连接多个数据库 phalcon multi-database
查看>>
React Native(十一)——按钮重复点击事件的处理
查看>>
zepto jquery和zepto的区别?
查看>>
机器学习笔记(4):多类逻辑回归-使用gluton
查看>>
26.angularJS $routeProvider
查看>>
内存映射函数remap_pfn_range学习——示例分析(2)
查看>>
年轻的工程师如何月入伍万XD
查看>>
NAT64与DNS64基本原理概述
查看>>
Java-Shiro(四):Shiro
查看>>
Oracle 备份、恢复单表或多表数据步骤
查看>>
ubuntu 步步为营之uclinux编译和移植(完整版)
查看>>
Lintcode: Partition Array
查看>>
sudo 之后 unable to resolve host的问题解决办法
查看>>
那些PHP中没有全称的简写
查看>>
【elasticsearch】python下的使用
查看>>
python字符串和编码
查看>>
JS实现表单多文件上传样式美化支持选中文件后删除相关项
查看>>