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 ...
随机推荐
- Python学习系列之logging模块
实例一:日志写进一个文件 代码: import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filen ...
- 零基础学python-3.2 变量赋值
这一节我们来具体展开变量赋值 1.以下我们举各种赋值的样例 anInt=12 anFloat=2.2 anStr='string' aList=['a','a','a'] anArray=(1,2,3 ...
- Java 实现 淘宝秒杀 聚划算 自己主动提醒 源代码
说明 本实例可以监控聚划算的抢购button,在聚划算整点聚的时间到达时自己主动弹开页面(URL自定义). 能够自己定义监控持续分钟数,同一时候还能够通过多线程加快刷新速度. 源代码 package ...
- unknownhostexception错误解决方案
关于java.net.UnknownHostException大家也许都比较熟悉,今天我来整理一下关于java.net.UnknownHostException的各种处理办法: 1.在Android项 ...
- Direct3D 9 入门样例程序 圆锥体
介绍 Directx3D 9 什么是DirectX,非常好说了,Win32 C++ API.主要是多媒体编程方面的,长处体如今高性能了,如今我知道的版本号最高是D3D11,可是我是学习入门的,从D3D ...
- python第三方库系列之十八--python/django test库
django是属于python语音的web框架,要说django測试.也能够先说说python的測试.django能够用python的方式測试,当然,django也基于python封装了一个自己的測试 ...
- python安装easy_install和pip
1 安装easy_install https://pypi.python.org/pypi/setuptools 下载setuptools 执行python setup.py install就安装成功 ...
- monitor and move the log content to our big data system
Apache Flume HDFS Sink Tutorial | HowToProgram https://howtoprogram.xyz/2016/08/01/apache-flume-hdfs ...
- BusyBox下ftpget的使用方法
在终端输入ftpget命令,可以得到以下帮助信息: BusyBox v1.17.4 (2010-12-22 10:59:18 CST) multi-call binary. Usage: ftpget ...
- 用redis实现动态时间段内统计排序
问题描述 需要根据某类数据在动态时间段内的统计值对这些数据进行排名.例如按过去24小时内点赞数排名的帖子,每隔一小时计算一次结果.以下描述均针对这个例子展开. 解决思路 针对这种问题,我的第一反应是直 ...