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. Xcode常见问题

    今天真机测试的时候,突然出现了这个错误:  not have an architecture that “Administrator”的 iPhone (3) can execute. 原因是我刚刚修 ...

  2. C++函数默认参数(转)

    在代码中使用到了函数的默认参数,在函数的定义和实现中都填写的默认参数,结果出现了错误: 代码: #ifndef FIRSTPAGE_H #define FIRSTPAGE_H #include < ...

  3. zepto与jquery冲突

    公司项目中一直用的都是zepto,但是jQuery扩展的插件比较多. jQuery有一个方法noConflict(),可以把jQuery的$改掉.var aa = $.noConflict();就用a ...

  4. sama5d3 环境检测 gpio--yx测试

    说明: yx0--pioA0 yx1--pioA2  yx2--pioA4  yx3--pioA10  yx4--pioA14  yx5--pioA16 yx6--pioA12 yx7--pioA20 ...

  5. JQuery元素选择

    1.基本元素选择器 $(“p”) //选取<p>元素 $(“p.info”) //选取所有class=”info”的<p>元素 $(“p#demo”) //选取id=”demo ...

  6. WINDOWS中设置计划任务执行PHP文件

    1.写一个PHP程序,命名为test.php,内容如下所示: <? $fp = fopen("test.txt", "a+"); fwrite($fp, ...

  7. VSS (Visual Source Safe 2005) 用法详解

    VSS用法指南 The usage of VSS (Visual Source Safe 2005) 1. 首先,当然是得安装好Visual Source Safe 2005 你可以在Visual S ...

  8. 数据库 Proc编程二

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...

  9. HTML的footer置于页面最底部的方法

    方法一:footer高度固定+绝对定位 <html> <head> <style type="text/css"> html{height:%; ...

  10. VBS 移除excel数据公式,只保留值

    如果将excel数据公式移除,只保留计算之后的值,将大大减少excel文件. 因为有上篇移除excel外部数据链接的经验,进行excel数据公式移除将快的多,方法如下. 首先我们得明白怎么手动移除ex ...