Codeforces - 466C - Number of Ways - 组合数学
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 - 组合数学的更多相关文章
- codeforces 466C. Number of Ways 解题报告
题目链接:http://codeforces.com/problemset/problem/466/C 题目意思:给出一个 n 个数的序列你,问通过将序列分成三段,使得每段的和都相等的分法有多少种. ...
- [Codeforces 466C] Number of Ways
[题目链接] https://codeforces.com/contest/466/problem/C [算法] 维护序列前缀和 , 枚举中间一段即可 , 详见代码 时间复杂度 : O(N) [代码] ...
- 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 ...
- cf466C Number of Ways
C. Number of Ways time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- 【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 ...
- 【Codeforces 466C】Number of Ways
[链接] 我是链接,点我呀:) [题意] 让你把数组分成3个连续的部分 每个部分的和要一样 问你有多少种分法 [题解] 先处理出来num[i] 表示i..n这里面有多少个j 满足aft[j] = af ...
- Codeforces 40E Number Table - 组合数学
题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...
- Codeforces 840C 题解(DP+组合数学)
题面 传送门:http://codeforces.com/problemset/problem/840/C C. On the Bench time limit per test2 seconds m ...
随机推荐
- COCOS学习笔记--重力感应Acceleration
Cocos2dx重力感应Acceleration,准确来说叫加速度计,加速度计能够感应设备上X.Y.Z轴方向上线性加速度的变化.事实上叫"重力感应"或"重力加速度计&qu ...
- UP Board USB无线网卡选购指南
前言 原创文章,转载引用务必注明链接,水平有限,欢迎指正. 本文环境:ubilinux 3.0 kernel 4.4.0 本文使用Markdown写成,为获得更好的阅读体验和正常的图片.链接,请访问我 ...
- weex 项目开发(一) weex create project 与 weex init project 的区别
开发环境配置:http://www.cnblogs.com/crazycode2/p/7822961.html 1. weex create project 与 weex init project ...
- HDU1114 Piggy-Bank 【全然背包】
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 2015 Multi-University Training Contest 3--1011 Work
代码: #include<cstdio> #include<cstring> using namespace std; int n,k; int father[105],son ...
- Eureka vs Zookeeper
著名的CAP理论指出,一个分布式系统不可能同时满足C(一致性).A(可用性)和P(分区容错性).由于分区容错性在是分布式系统中必须要保证的,因此我们只能在A和C之间进行权衡.在此Zookeeper保证 ...
- 笔记整理--LibCurl开发
LibCurl开发_未了的雨_百度空间 - Google Chrome (2013/7/26 21:11:15) LibCurl开发 一:LibCurl 编程流程1.调用curl_global_ini ...
- IOS------Warning
本文转载至 http://blog.csdn.net/shijiucdy/article/details/8755667 处理警告: 1,Validate Project Settings(updat ...
- DOM操作一
1.通过ID选取元素 var section = document.getElementById("section1"); 2.通过ID查找多个元素 function getEle ...
- CH 5402 选课(分组背包+树形DP)
CH 5402 选课 \(solution:\) 很有讨论套路的一道题,利用树的结构来表示出不同课程之间的包含关系(这里还要建一个虚点将森林变成一颗打大树).然后用子树这个概念巧妙的消除了因为这些包含 ...