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 all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices
i, j (2 ≤ i ≤ j ≤ n - 1), that
.
The first line contains integer n
(1 ≤ n ≤ 5·105), showing how many numbers are in the array. The second line contains
n integers a[1],
a[2], ..., a[n]
(|a[i]| ≤ 109) — the elements of array
a.
Print a single integer — the number of ways to split the array into three parts with the same sum.
5
1 2 3 0 3
2
4
0 1 -1 0
1
2
4 1
0
思路:若平分分成若干种情况。应当总体(SUM)考虑,对SUM/3进行分析。它是区分3段的标准。
所以当部分和tmp==SUM/3,部分统计加一。
当tmp==sUM*2/3。则所有统计ans+=部分统计(s);
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#define LL __int64
#define inf 0x3f3f3f3f
using namespace std;
LL a[1000000];
int main()
{
LL n,m,i,j,k;
LL b,t;
while(~scanf("%I64d",&n))
{
LL z=0;
for(i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
z+=a[i];
}
if(z%3)
{
printf("0\n");
continue;
}
z/=3;
LL ans=0;LL s=0;LL tmp=0;
for(i=0;i<n-1;i++)//注意舍去最后以为数<span id="transmark"></span>
{
tmp+=a[i];
if(z*2==tmp)
{
ans+=s;
}
if(z==tmp)
{
s++;
}
}
printf("%I64d\n",ans);
}
return 0;
}
Codeforces Round #266 (Div. 2) C. Number of Ways的更多相关文章
- Codeforces Round #266 (Div. 2)
http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...
- Codeforces Round #266 (Div. 2) D
D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #266 (Div. 2)-C,D
C - Number of Ways 直接暴力从前往后寻找.假设找到1/3sum的位置,那么标记++.找到2/3的位置,总数加上标记数. #include<stdio.h> #includ ...
- Codeforces Round #651 (Div. 2) C. Number Game(数论)
题目链接:https://codeforces.com/contest/1370/problem/C 题意 给出一个正整数 $n$,Ashishgup 和 FastestFinger 依次选择执行以下 ...
- Codeforces Round #266 (Div.2) B Wonder Room --枚举
题意:给出一个两边长为a,b的矩形,要求增加a和增加b使a*b>=6*n且a*b最小. 解法:设新的a,b为a1,b1,且设a<b,那么a<=a1<=ceil(sqrt(6*n ...
- Codeforces Round #266 (Div. 2)B(暴力枚举)
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...
- Codeforces Round #674 (Div. 3) F. Number of Subsequences 题解(dp)
题目链接 题目大意 给你一个长为d只包含字符'a','b','c','?' 的字符串,?可以变成a,b,c字符,假如有x个?字符,那么有\(3^x\)个字符串,求所有字符串种子序列包含多少个abc子序 ...
- Codeforces Round #686 (Div. 3) E. Number of Simple Paths (思维,图,bfs)
题意:有一个\(n\)个点,\(n\)条边的图,问你长度至少为\(1\)的简单路径有多少条. 题解:根据树的性质,我们知道这颗树一定存在一个环,假如一棵树没有环,那么它的所有长度不小于\(1\)的简单 ...
- Codeforces Round #651 (Div. 2) C. Number Game (博弈,数学)
题意:对于正整数\(n\),每次可以选择使它变为\(n-1\)或者\(n/t\) (\(n\ mod\ t=0\)且\(t\)为奇数),当\(n=1\)时便不可以再取,问先手赢还是后手赢. 题解:首先 ...
随机推荐
- The eleven Day
库操作 一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息.字符信息等 performance_schema ...
- 【php】 get 和 post 比较
来源 php.net 评论区 -- nucc1 worth clarifying: POST is not more secure than GET. The reasons for choosing ...
- PowerShell-第2章 管道
2.1 过滤列表项或命令输出项 列出所有正在运行进程名称中包含"search"的进程,对进程名字属性使用-like操作符来比较进程的Name属性 Get-Process | Whe ...
- sql优化工具--美团SQLAdvisor
美团点评SQL优化工具SQLAdvisor开源 介绍 在数据库运维过程中,优化 SQL 是 DBA 团队的日常任务.例行 SQL 优化,不仅可以提升程序性能,还能够降低线上故障的概率. 目前常用的 S ...
- linux 安装SNV服务
1.安装vnc server[root@pxe ~]# yum install tigervnc-server -y 2.设置 vnc server 开机启动[root@pxe ~]# chkconf ...
- server 08 R2 NBL 报错:RPC 服务器在指定计算机上不可用
排查步骤如下: 1.检查并确保 Remote Procedure Call (RPC) 和 Remote Procedure Call (RPC) Locator这两项服务是否都已经启动 2.确认此2 ...
- luogu3755 [CQOI2017]老C的任务
扫描线水题. #include <algorithm> #include <iostream> #include <cstdio> using namespace ...
- UIDatePicker 显示时间和打印时间不一样
默认是时区为0,如下格式化一下就好啦 UIDatePicker *datePiker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 100, ...
- python 中zip()函数的使用
zip(*iterables)函数的定义: zip()函数的对象Iterables,iterables可以有多个参数(元组,列表等可迭代对象)组成.通过zip()函数返回一组元组数据,每个元组中的第i ...
- 【转】DCOM远程调用权限设置
原文:https://blog.csdn.net/ervinsas/article/details/36424127 最近几天被搞得焦头烂额,由于DCOM客户端程序是在32位系统下开发的,调试时DCO ...