Code Forces 21C Stripe 2
1 second
64 megabytes
standard input
standard output
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 three pieces so that the sum of numbers from
each piece is equal to the sum of numbers from any other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
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 the amount of ways to cut the stripe into three non-empty pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
4
1 2 3 3
1
5
1 2 3 4 5
0
切割两个点,那么两个点到顶点的区间和肯定是总和的3分之1.对于每个点找到他右边有多少个满足条件的点,
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
int n;
long long int a[100005];
long long int s[100005];
int l[100005];
int r[100005];
long long int sum;
int main()
{
scanf("%d",&n);
s[0]=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
s[i]=s[i-1]+a[i];
sum+=a[i];
}
if(sum%3!=0||n<=2)
{printf("0\n");return 0;}
int cnt=0;int cot=0;
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
for(int i=n;i>=1;i--)
{
if(s[n]-s[i-1]==sum/3)
{
r[i]=r[i+1]+1;
}
else
r[i]=r[i+1];
}
long long int ans=0;
for(int i=1;i<=n;i++)
{
if(s[i]==sum/3)
{
int x=r[i+2]; ans+=x;
}
}
printf("%lld\n",ans);
return 0; }
Code Forces 21C Stripe 2的更多相关文章
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
- code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)
Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...
- code forces 382 D Taxes(数论--哥德巴赫猜想)
Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...
- code forces Watermelon
/* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...
- code forces Jeff and Periods
/* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...
- Code Forces Gym 100971D Laying Cables(单调栈)
D - Laying Cables Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- atitit.研发管理--标准化流程总结---java开发环境与项目部署环境的搭建工具包总结
atitit.研发管理--标准化流程总结---java开发环境与项目部署环境的搭建工具包总结 1. ide系列(只开发环境需要,但部署环境也做好放上,很有用) 1 2. web服务器+sdk+网站程序 ...
- atitit.集合的filt操作细分 filter总结
atitit.集合的filt操作细分 filter总结 1. Css sltr 1 2. 基本选择器(根据id,class,元素名) 2 3. 层次选择器 3 4. 过滤选择器 3 5. First, ...
- 常用Linux shell命令汇总
1.检查远程端口是否对bash开放:echo >/dev/tcp/8.8.8.8/53 && echo "open" 2.让进程转入后台:Ctrl + z 3 ...
- python内置函数之dict()
class dict(**kwargs) 返回一个字典.本方法用来创建一个字典对象.只能传入一个参数. >>> dict(a=1) {'a': 1} 也可以传入映射函数作为参数 &g ...
- 2018.7.13vue知识小结
//配置是否允许vue-devtools检查代码,方便调试,生产环境中需要设置为false Vue.config.devtools=false; Vue.config.productionTip=fa ...
- line: 1: Syntax error: word unexpected (expecting ")")
开发板上运行可执行程序报出错误: line1: 1: Syntax error: word unexpected (expecting ")") 解决思路: 1.编译器的问题 用a ...
- SAP ECC6安装系列二:安装前的准备工作
原作者博客 http://www.cnblogs.com/Michael_z/ ======================================== 安装 Java 1,安装 Java, ...
- 为什么 Windows API 使用 stdcall 调用约定?
作者:知乎用户链接:https://www.zhihu.com/question/31453641/answer/52001143来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- jquery.autocomplete 传参问题
今天遇到一个问题,我需要传一个文本库的内容给后台,然后用autocomplete显示内容,开始觉得很简单 不就是 function SalePrice_Complete(text) { //分割拿到索 ...
- C语言 百炼成钢24
/* 题目60:从键盘中输入一个不超过40个字符的字符串, 再输入3个位数(每次删除一个字符),删除对应 位数的字符,然后输出删除指定字符后的字符串. 输入:hellokityManGood 3 6 ...