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. leetcode笔记:Contains Duplicate

    一. 题目描写叙述 Given an array of integers, find if the array contains any duplicates. Your function shoul ...

  2. Android源代码解析之(三)--&gt;异步任务AsyncTask

    转载请标明出处:一片枫叶的专栏 上一篇文章中我们解说了android中的异步消息机制. 主要解说了Handler对象的使用方式.消息的发送流程等.android的异步消息机制是android中多任务处 ...

  3. 线程特定数据TSD总结

    一线程的本质 二线程模型的引入 三线程特定数据 四关键函数说明 五刨根问底啥原理 六私有数据使用演示样例 七參考文档 一.线程的本质 Linux线程又称轻量进程(LWP),也就说线程本质是用进程之间共 ...

  4. js中cookie的使用具体分析

                   JavaScript中的还有一个机制:cookie,则能够达到真正全局变量的要求. cookie是浏览器 提供的一种机制,它将document 对象的cookie属性提供 ...

  5. c程序设计语言第一章5

    练习1.20请编写程序d e t a b

  6. windows 怎么验证域名是否开启了 https

    由于 ping 是针对 IP 层的,只能检查当前系统网络与网络中某个IP,某个域名是否连通. 当我们需要验证域名是否开启了 https时,用如下方法: 1. 下载tcping.exe,放到本机C盘根目 ...

  7. MCE----Machine-check exception

    http://en.wikipedia.org/wiki/Machine_Check_Exception Machine-check exception From Wikipedia, the fre ...

  8. JOIN ,LEFT JOIN ,ALL JOIN 等的区别和联系

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录  right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) ...

  9. HDU 5666 Segment

    Segment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  10. 小玩Spring Boot

    Spring Boot是Spring Mvc的升级版 号称是替代者 也是微服务的微框架基础 有3启动方式 用IntelJ IDEA 生成spring boot工程 1.有个入口类 可以直接run as ...