CodeForces 21C Stripe 2 构造题
题目链接:
题目链接:点击打开链接
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <math.h>
using namespace std;
#define inf 10000000
#define N 100050
#define ll __int64
ll n;
ll a[N], lsum[N], rsum[N];
ll lok[N], rok[N];
int main(){
ll i, j;
while(cin>>n) {
ll sum = 0;
bool siz = false;
for(i=1;i<=n;i++)cin>>a[i], sum += a[i], siz |= a[i];
if(!siz) {
cout<<(n-1)*(n-2)/2<<endl;
continue;
}
if(sum%3){puts("0");continue;}
sum/=3;
lsum[0] = 0;
for(i=1;i<=n;i++)lsum[i] = lsum[i-1]+a[i];
rsum[n+1] = 0;
for(i=n;i;i--)rsum[i] = rsum[i+1]+a[i];
memset(lok, 0, sizeof lok);
memset(rok, 0, sizeof rok);
for(i=1;i<=n;i++) {
if(lsum[i]==sum){
lok[i] = 1;
}
// if(i==n)lok[i]=0;
// lok[i] += lok[i-1];
} for(i=n;i;i--) {
if(rsum[i]==sum){
rok[i] = 1;
}
rok[i]+=rok[i+1];
}
ll ans = 0;
for(i = 1; i+2<=n; i++)
ans += lok[i] * rok[i+2];
// ll ans = (lok[n]*(lok[n]-1))/2;
cout<<ans<<endl;
}
return 0;
}
/*
7
-1 1 -1 1 -1 1 0
9
-5 -2 1 1 5 0 -4 4 0
100
3 0 -5 2 -3 -1 -1 0 -2 -5 -4 2 1 2 -2 -1 -1 -4 3 -1 -3 -1 5 0 -4 -4 -1 0 -2 -2 0 1 -1 -2 -1 -5 -4 -2 3 1 -3 0 -1 1 0 -1 2 0 -2 -1 -3 1 -2 2 3 2 -3 -5 2 2 -2 -2 1 2 -2 -1 3 0 -4 7 -2 2 1 4 -9 -1 -2 -1 0 -1 0 -2 -2 -1 1 1 -4 2 -3 -3 7 1 1 -3 -7 0 -2 0 5 -2 */
CodeForces 21C Stripe 2 构造题的更多相关文章
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 2, ....... ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- B - Save the problem! CodeForces - 867B 构造题
B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错 ...
- Codeforces 1491G - Switch and Flip(构造题)
Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \( ...
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ...
- cf251.2.C (构造题的技巧)
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...
- hdu4671 Backup Plan ——构造题
link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostrea ...
- BZOJ 3097: Hash Killer I【构造题,思维题】
3097: Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 963 Solved: 36 ...
- Codeforces 1045E. Ancient civilizations 构造 计算几何 凸包
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1045E.html 4K码量构造题,CF血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. ...
随机推荐
- java之Thread.sleep(long)与object.wait()/object.wait(long)的区别(转)
一.Thread.sleep(long)与object.wait()/object.wait(long)的区别sleep(long)与wait()/wait(long)行为上有些类似,主要区别如下:1 ...
- 转:Bootstrap研究 精巧的网格布局系统
本网格布局系统属于Scaffolding(框架,布局)部分.在Scaffolding里面有(固定)网格布局(Grid System)和流式网格布局(Fluid Grid System).本文讨论第一种 ...
- svn笔记2
Examining History Your Subversion repository is like a time machine. It keeps a record of every chan ...
- UVALive 5797 In Braille
题目 比赛总结 题意:给出1-9的盲文,每种盲文都是2×3的点阵,有些点是凸起的用*表示,其余的用.表示.要进行两种操作,1 把盲文变成数字,2 把数字变成盲文 解法:按规则模拟....注意读入的每个 ...
- HDU 4617Weapon(两条异面直线的距离)
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- Search Insert Position--寻找插入点Given a sorted array and a target value, return the index if the target
问题:链接 Given a sorted array and a target value, return the index if the target is found. If not, retu ...
- vc中关于 directx的配置,和dxsdk_extras(directshow)
2009-11-10 0:28 此文章:自己编写 转载于<汤姆&杰瑞> DirectShow 1 -- 下载与VC配置 1 DirectX SDK9 Directshow sd ...
- inheritAll 及 ant antfile案例分析
<?xml version="1.0"?> <project name="a" default="targeta"> ...
- 浅谈HTML之模仿人人网登陆界面(新手必学)
为方便大家对web相关知识的了解,现谈谈新手如何从HTML css Javascript到以后后台的发展.首先,让大家看看HTML仿人人登陆界面: <!doctype html> < ...
- xp对opengl的支持问题
我在项目中遇到的xp显示问题是因为xp对opengl的支持问题,是通过void QCoreApplication::setAttribute(Qt::ApplicationAttribute attr ...