C. Stripe 2
time limit per test

1 second

memory limit per test

64 megabytes

input

standard input

output

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?

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 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.

Examples
input
4
1 2 3 3
output
1
input
5
1 2 3 4 5
output
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的更多相关文章

  1. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  2. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  3. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  4. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  5. 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 ...

  6. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  7. code forces Watermelon

    /* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...

  8. code forces Jeff and Periods

    /* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...

  9. Code Forces Gym 100971D Laying Cables(单调栈)

    D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. Hystrix的用法

    package com.example.demo; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; imp ...

  2. ISTQB测试人员认证 初级(基础级)大纲

    ISTQB测试人员认证 初级(基础级)大纲 ---中文修订版本1(2015年5月6日) 2015-06-22 大纲pdf下载  ISTQB资料中心 在课程大纲中,每个章节都会提供相应的认知水平要求: ...

  3. dp之01背包hdu2639(第k优解)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:给出一行价值,一行体积,让你在v体积的范围内找出第k大的值.......(注意,不要 和它的第一题混 ...

  4. github上搭建网站前台页面

    其实就是把html页面提交到github,为了能在线演示: 1. 首先在github网站找到你的项目 2. 点击设置 3. 找到这几个选项,选择master branch打钩,然后保存 4. 然后就会 ...

  5. Idea上配置btm

    1.  先在eclipse中配置好项目,再讲配置好的项目导入到idea中

  6. memcached server LRU 深入分析

    Memcached,人所皆知的remote distribute cache(不知道的可以javaeye一下下,或者google一下下,或者baidu一下下,但是鉴于baidu的排名商业味道太浓(从最 ...

  7. C++中变量做数组长度

    在Java中,这是完全可以的,比如我们运行如下程序: package cn.darrenchan.storm; import java.util.Arrays; public class Test { ...

  8. 关于spring中注解和xml混合使用

    可以混合用.文档有说明: Spring can accommodate both styles and even mix them together. 混合用的话,有个先后顺序,xml配置会覆盖ann ...

  9. imx6 18bit display

    imx6 kernel中使用18bit的lcd,uboot中bootargs参数bpp=32,lcd才能够正常显示. "bootargs=console=ttymxc0,115200 ini ...

  10. linux grub启动密码验证设置

    1.认识启动配置选项 [root@server5 ~]# cat /boot/grub/grub.conf      # grub.conf generated by anaconda # # Not ...