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. LVM创建

    LVM介绍 PV(Physical Volume) - 物理卷 物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘,也可以是raid设备 VG(Volume Group ...

  2. Android 使用ListView的A-Z字母排序功能实现联系人模块

    在上一篇文章其中,主要学习了ListView的A-Z字母排序功能以及依据输入框的输入值改变来过滤搜索结果,假设输入框里面的值为空.更新为原来的列表,否则为过滤数据列表,包含汉字转成拼音的功能.假设你还 ...

  3. INAPP登陆调用的FB接口

    public function login_get (){ $this->load->helper ( 'auth' ); $redirectUrl = $this->input-& ...

  4. Oracle启动和关闭服务

    Oracle须要启动和关闭的服务: 1.OracleOracle_homeTNSListener     相应于数据库的监听程序 2.OracleServiceSID                 ...

  5. linux安装jdk tomcat nginx 以及常用命令

    linux: 操作系统,应用服务器上 常用命令: cd 切换命令 cd / cd ~ cd ../../ cd xx ll 展示所有的文件 ll -h 友好的展示 mkdir 创建目录 mkdir 目 ...

  6. Robot Framework自己主动化測试框架之我见

    一些自己主动化測试现状: 盲目的去做自己主动化,终于以失败告终. 觉得是能提高效率的事情.却推广不下去: 事实上上述问题产生的原因是: 自己主动化測试案例稳定性不高,可维护性比較差: 自己主动化測试工 ...

  7. WPF中如何使用代码操作数据模板生成的控件

    有一个Listbox,里面的Item是通过数据模板生成的,如下所示: <Border Margin="15" BorderBrush="Aqua" Bor ...

  8. Java网络编程知识点(1)

    怎样将一个String对象转换成InputStream对象? ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBy ...

  9. ResultSetMetaData类的介绍

    ResultSetMetaData .DatabaseMetaData中的方法介绍 利用ResultSet的getMetaData的方法可以获得ResultSetMeta对象,而ResultSetMe ...

  10. SyntaxError:Strict mode does not allow function declaration in a lexically nested statement.

    问题描述   使用react-native init创建了一个新项目,在package.json中使用的react-native的版本如下: "dependencies": { & ...