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 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
随机推荐
- vbox在共享文件夹设置链接报错Protocol error问题
环境: 基于VBox 的 vagrant (centos版本)开发环境. 问题: Virtualbox 虚拟机(centOS)中,在进行go程序编译的时候,需要设置一个链接符,然后得到了如下的错误: ...
- Go语言_RPC_Go语言的RPC
一 标准库的RPC RPC(Remote Procedure Call,远程过程调用)是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络细节的应用程序通信协议.简单的说就是要像调用本地函数 ...
- 简单过下bash/sh脚本基本知识吧
1.sh/bash要注意空格的使用 2. for循环: for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ &q ...
- 微服务指南走北(三):Restful API 设计简述
API的定义取决于选择的IPC通信方式,假设是消息机制(如 AMQP 或者 STOMP).API则由消息频道(channel)和消息类型.假设是使用HTTP机制,则是基于请求/响应(调用http的ur ...
- 赞一下TMS Software 和 AdvStringGrid
非常久前给Support发Email问能不能在设计期给AdvStringGrid标题加个数字标识.每次我都是自己改代码加上去.这次升级到新版本号,没想到增加了这个功能: 功能虽小可是非常有用,非常多的 ...
- vue2.0 vue-router
一.SPA中路由的简单实现 main.js import Vue from 'vue' import App from './App' import VueRouter from 'vue-route ...
- python(37)- 软件开发规范
软件开发规范 一.为什么要设计好目录结构? 1.可读性高: 不熟悉这个项目的代码的人,一眼就能看懂目录结构,知道程序启动脚本是哪个,测试目录在哪儿,配置文件在哪儿等等.从而非常快速的了解这个项目. 2 ...
- 【HDOJ 5654】 xiaoxin and his watermelon candy(离线+树状数组)
pid=5654">[HDOJ 5654] xiaoxin and his watermelon candy(离线+树状数组) xiaoxin and his watermelon c ...
- leetCode 104.Maximum Depth of Binary Tree(二叉树最大深度) 解题思路和方法
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Linux驱动经典面试题目
1. linux驱动分类 2. 信号量与自旋锁 3. platform总线设备及总线设备怎样编写 4. kmalloc和vmalloc的差别 5. module_init的级别 6. 加入 ...