[Codeforces 466C] Number of Ways
[题目链接]
https://codeforces.com/contest/466/problem/C
[算法]
维护序列前缀和 , 枚举中间一段即可 , 详见代码
时间复杂度 : O(N)
[代码]
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + ; int a[MAXN];
long long sum[MAXN]; template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ int n;
read(n);
for (int i = ; i <= n; i++)
{
read(a[i]);
sum[i] = sum[i - ] + a[i];
}
if (sum[n] % != )
{
printf("0\n");
return ;
}
long long value = sum[n] / , ans = , cnt = ;
for (int i = ; i < n; i++)
{
if (sum[i] != * value)
{
if (sum[i] == value) cnt++;
continue;
}
ans += cnt;
if (sum[i] == value) cnt++;
}
printf("%I64d\n",ans); return ; }
[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/problemset/problem/466/C 要把数据分为均等的非空的三组,那么每次确定第二个分割点的时候把(除此之外的)第一个分割点的数目加上就可以 ...
- 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 Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
随机推荐
- 零基础入门学习Python(11)--列表:一个打了激素的数组(2)
前言 上节课我们介绍一个打了激素的数组,叫做列表.列表我们比作一个大仓库,你所能够具现化的东西,都可以往里面扔,它包罗万象.另外还介绍了三个往列表添加元素的方法,分别是: append(),exten ...
- (八)python3 迭代
迭代:如果给定一个 list 或 tuple,我们可以通过 for 循环来遍历这个 list 或tuple,这种遍历我们称为迭代(Iteration) 字典: >>> d = {'a ...
- MyBaties异常之 ORA-00918: 未明确定义列
原因: 如果a表与b表连接,且a与b中存在两个相同的字段,则必须指明字段是哪个表的 箭头所致位置没有指定ROOM_ID为那个表的,应修改为t1.ROOM_ID
- mysql复制知识整理
主服务器(master)简称M,从服务器(slave)简称S 一.原理: M监听S的复制请求,S创建一个I/O线程以连接M并让它发送记录在其二进制日志中的语句,M接受到请求,创建一个Binlog ...
- noip模拟赛 集合
分析:感觉像是贪心,再看数据范围这么大,肯定是贪心没错.但是要怎么贪呢?主要的思想是让每次往上加的数尽量多,肯定要先把0分裂,如果能正好一起跳到最终状态就好.举个例子:5,3,2,1,最大值比次大值大 ...
- 【(待重做)树状数组+dp+离散化】Counting Sequences
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/G [题意] 给定一个数组a,问这个数组有多少个子序列,满足子序列中任意两个相邻数 ...
- 2.3 comparator(比较器)
1.comparator是java的一种机制,用来帮助我们给相同对象的不同属性排序 2.Comparable接口,是一个对象本身就已经支持自比较所需要实现的接口,如String,Integer自己就已 ...
- hdu - 1704 Rank(简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1704 遇到标记过的就dfs,把隐含的标记,最后计数需要注意. #include <cstdio> # ...
- Uva 106 - Fermat vs. Pythagoras 解题报告
数论题,考查了本原勾股数(PPT) 对一个三元组(a,b,c)两两互质 且满足 a2 + b2 = c2 首先有结论 a 和 b 奇偶性不同 c总是奇数(可用反证法证明,不赘述) 设 a为奇数 b为偶 ...
- 【.Net 学习系列】-- 反射的简单用法
新建两个项目:类库(Model)和控制台应用程序(ReflectTest). 在[Model]中添加一个类[User]: namespace Model { public class User { p ...