https://codeforces.com/problemset/problem/466/C

要把数据分为均等的非空的三组,那么每次确定第二个分割点的时候把(除此之外的)第一个分割点的数目加上就可以了。记得最后给第三组留至少一个。

#include<bits/stdc++.h>
using namespace std;
#define ll long long int n;
int a[]; int main(){
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]); ll sum=;
for(int i=;i<n;i++){
sum+=a[i];
} if(sum%!=){
puts("");
return ;
} ll d=sum/;
int z1=; ll cnt=; ll cur=;
int inc=; int i=;
while(i<n){
cur+=a[i];
if(cur==d){
z1++;
inc=;
}
else{
inc=;
} if(z1>=){
if(cur==2ll*d){
if(i<=n-){
//至少把最后一个n-1留给第三组
if(inc)
cnt+=z1-;
else
cnt+=z1;
//printf("cnt=%lld i=%d\n",cnt,i);
}
}
}
i++;
} printf("%lld\n",cnt);
}

Codeforces - 466C - Number of Ways - 组合数学的更多相关文章

  1. codeforces 466C. Number of Ways 解题报告

    题目链接:http://codeforces.com/problemset/problem/466/C 题目意思:给出一个 n 个数的序列你,问通过将序列分成三段,使得每段的和都相等的分法有多少种. ...

  2. [Codeforces 466C] Number of Ways

    [题目链接] https://codeforces.com/contest/466/problem/C [算法] 维护序列前缀和 , 枚举中间一段即可 , 详见代码 时间复杂度 : O(N) [代码] ...

  3. Codeforces Round #266 (Div. 2) C. Number of Ways

    You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split ...

  4. cf466C Number of Ways

    C. Number of Ways time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. LeetCode 5274. Number of Ways to Stay in the Same Place After Some Steps - Java - DP

    题目链接:5274. 停在原地的方案数 You have a pointer at index 0 in an array of size arrLen. At each step, you can ...

  6. 【leetcode】1269. Number of Ways to Stay in the Same Place After Some Steps

    题目如下: You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 positio ...

  7. 【Codeforces 466C】Number of Ways

    [链接] 我是链接,点我呀:) [题意] 让你把数组分成3个连续的部分 每个部分的和要一样 问你有多少种分法 [题解] 先处理出来num[i] 表示i..n这里面有多少个j 满足aft[j] = af ...

  8. Codeforces 40E Number Table - 组合数学

    题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...

  9. Codeforces 840C 题解(DP+组合数学)

    题面 传送门:http://codeforces.com/problemset/problem/840/C C. On the Bench time limit per test2 seconds m ...

随机推荐

  1. vmware下安装mac os虚拟机问题,最后还是最终攻克了被一个小失误给陷害了

    今天决定来体验一下苹果系统.虚拟机文件大概用了一天半时间才下载完毕,解压后是39G大小,赶紧安装VMWARE.然后载入虚拟机文件体验.開始当我苹果标志出来的时候,我以为成功了.但是那个小齿轮一直在转, ...

  2. 读取xml生成lua測试代码

    #include <iostream> #include <string> #include <fstream> #include "tinyxml2.h ...

  3. 时间格式 2016-08-15T16:00:00.000Z

    我修改的时间是2016-08-16(转换成Date后默认为2016-08-16 00:00:00),而我得到的时间却是2016-08-15T16:00:00.000Z 联想到我们当前的时区是+8区   ...

  4. 【Leetcode】经典的Jump Game in JAVA

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  5. maven插件介绍之maven-jar-plugin

    maven-jar-plugin 插件的maven依赖为: <dependency> <groupId>org.apache.maven.plugins</groupId ...

  6. Spark 学习笔记:(二)编程指引(Scala版)

    参考: http://spark.apache.org/docs/latest/programming-guide.html 后面懒得翻译了,英文记的,以后复习时再翻. 摘要:每个Spark appl ...

  7. Python 003- 小知识汇总(更新中)

    #查询key是否存在,可以在使用未知的字典的时候使用 #-*- coding:utf-8 -*- D={'a':1,'c':3,'b':2} for key in sorted(D): print(k ...

  8. 常用SQL备忘录

    联表删除: delete t1,t2 from table_name t1 left join t2 on t1.id=t2.id where t1.id=23 (ps:该语句在mysql 5.0之前 ...

  9. UIPageControll 的属性和用法

    UIPageControll 是继承于UIControl的一个IOS系统UI控件,可以提供给开发者设计分页效果的功能. 初始化方法 UIPageControl * page = [[UIPageCon ...

  10. 隐马尔科夫模型HMM

    崔晓源 翻译 我们通常都习惯寻找一个事物在一段时间里的变化规律.在很多领域我们都希望找到这个规律,比如计算机中的指令顺序,句子中的词顺序和语音中的词顺序等等.一个最适用的例子就是天气的预测. 首先,本 ...