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 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
随机推荐
- 如何轻松的把图片导入execl表格中
在项目中有时候会遇到往数据库中导数据的时候,往往需要把图片也一起导入execl表格中,那怎么才能把图片一块导入至execl中呢?那么今天我们就来看看怎么实现吧! 如何实现?今天我们就来用jxl和poi ...
- 四个很好的开源app项目
Open Source and the iOS App Store Today, we are open-sourcing 4 iOS apps: ThatInbox, an email client ...
- 【redis】5.spring boot项目中,直接在spring data jpa的Repository层使用redis +redis注解@Cacheable直接在Repository层使用,报错问题处理Null key returned for cache operation
spring boot整合redis:http://www.cnblogs.com/sxdcgaq8080/p/8028970.html 首先,明确一下问题的场景 之前在spring boot整合re ...
- Access自定义函数(人民币大写)
人民币大写函数:整数不超过13位. Public Function 人民币大写(A) As String Dim aa As String Dim bb As String Dim cc As Str ...
- [反汇编练习] 160个CrackMe之035
[反汇编练习] 160个CrackMe之035. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- stateMachine 相关知识
一个state的基本构造,processMessage 以及可选的enter exit 和getName. processMessager是用于处理数据. enter 和exit 则是类似于 面向编程 ...
- openssl之EVP系列之11---EVP_Verify系列函数介绍
openssl之EVP系列之11---EVP_Verify系列函数介绍 ---依据openssl doc/crypto/EVP_VerifyInit.pod翻译和自己的理解写成 (作者 ...
- PS 如何用制作键盘图标
1 键盘可以大致分为笔记本键盘和台式机键盘,颜色一般是黑色或白色.不同的键盘,拍摄角度不同(俯视或者平视)得到的效果也不一样.一般我们根据自己需要得到需要的键盘形式.比如下面别人制作的一套立体键盘,立 ...
- ios You app information could not be saved. Try again. If the problem persists, contact us
ios You app information could not be saved. Try again. If the problem persists, contact us 大概意思:你的a ...
- css3 position fixed居中的问题
通常,我们要让某元素居中,会这样做: #element{ margin:0 auto; } 假设还想让此元素位置固定呢?一般我们会加入position:fixed,例如以下: #element{ po ...