codeforces 466C. Number of Ways 解题报告
题目链接:http://codeforces.com/problemset/problem/466/C
题目意思:给出一个 n 个数的序列你,问通过将序列分成三段,使得每段的和都相等的分法有多少种。
这个是详细的题解:
http://codeforces.com/blog/entry/13758

代码也是按这个思路来做的,可怜我的做法改了 N 次总是得不到正确的结果~~泪
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; typedef __int64 ll; const int maxn = 5e5 + ;
ll a[maxn], sum[maxn];
ll cnt[maxn]; int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
memset(sum, , sizeof(sum));
memset(cnt, , sizeof(cnt)); for (int i = ; i <= n; i++)
{
scanf("%I64d", &a[i]);
sum[i] = sum[i-] + a[i];
}
ll ans = ;
if (sum[n] % == )
{
ll avg = sum[n] / ; for (int i = n-; i; i--)
{
cnt[i] = cnt[i+]; // 不断往前传递
if (sum[i] == avg)
ans += cnt[i];
if (sum[i] == avg * ) // 可以分成三段的标志
cnt[i]++;
}
}
printf("%I64d\n", ans);
}
return ;
}
codeforces 466C. Number of Ways 解题报告的更多相关文章
- Codeforces - 466C - Number of Ways - 组合数学
https://codeforces.com/problemset/problem/466/C 要把数据分为均等的非空的三组,那么每次确定第二个分割点的时候把(除此之外的)第一个分割点的数目加上就可以 ...
- [Codeforces 466C] Number of Ways
[题目链接] https://codeforces.com/contest/466/problem/C [算法] 维护序列前缀和 , 枚举中间一段即可 , 详见代码 时间复杂度 : O(N) [代码] ...
- 【LeetCode】91. Decode Ways 解题报告(Python)
[LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- LeetCode:Decode Ways 解题报告
Decode WaysA message containing letters from A-Z is being encoded to numbers using the following map ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
随机推荐
- iOS 改变Search Bar中Scope Button中文本的颜色和字体
- (void)initSearchbar{ self.wineSearchBar.delegate = self; [self.wineSearchBar setScopeBarButtonTitl ...
- .Net ToString Format [转]
源文 :http://blog.csdn.net/luyifeiniu/article/category/25663/2 stringstr1 =string.Format("{0:N1}& ...
- Redis及其Sentinel配置项详细说明
Redis及其Sentinel配置项详细说明 http://lixiaohui.iteye.com/blog/2315516
- 没有IP地址的主机怎样保持IP层联通
在<两台不同网段的PC直连能否够相互ping通>一文中,我有点像在玩旁门左道,本文中.我继续走火入魔.两台机器,M1和M2,各自有一个网卡eth0,配置例如以下:M1的配置:eth0上不配 ...
- 【HDOJ 2089】不要62
[HDOJ 2089]不要62 第一个数位dp的题 做的老困难了...只是好歹是做出来了 迈出了第一步.. 对大牛来说这样的题都是小case ps:新上一个记忆化方法 一些绕弯的题里用dfs好想些 代 ...
- HDOJ题目2089 不要62(数位DP)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- [RFC] Simplifying kernel configuration for distro issues
http://lwn.net/Articles/507276/ From: Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b-A ...
- Mataplotlib事例操作
刚开始需要的文件是和前边的两个连载一起的
- YAML 对中文的处理
from yaml import load,dump f = open('xx.ymal',encoding='utf-8') l = load(f) print(f) w = open('xx_co ...
- 在Fedora25上轻松安装Cuda8
http://blog.csdn.net/u010158659/article/details/53592891 Cuda 8对于Pacal架构的英伟达新一代显卡(GTX 1070/1080/Tita ...