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血腥残暴! 题解 首先,如果所有点颜色相同,那么直接连个菊花搞定. ...
随机推荐
- CPU满格的元凶,这回是由于QTimer引起的(默认interval是0,太猛)
timer_space = new QTimer(); qDebug() << SystemGlobal::m_app->SpaceUse; qDebug() << ti ...
- html中事件处理中的this和event对象
在用js编写页面事件处理代码时,会经常涉及到this和event对象,但有时在采用不同的事件处理,尤其是在与自定义的对象关联时,这些对象的指向变的有些复杂. 本文来详细介绍下各种场景下 这些对象 真正 ...
- hadoop安全模式
hadoop安全模式在分布式文件系统启动的时候,开始的时候会有安全模式,当分布式文件系统处于安全模式的情况下,文件系统中的内容不允许修改也不允许删除,直到安全模式结束.安全模式主要是为了系统启动的 ...
- 基于visual Studio2013解决算法导论之020单链表
题目 单链表操作 解决代码及点评 #include <iostream> using namespace std; struct LinkNode { public: LinkNo ...
- Servlet 实现文件的上传与下载
这段时间尝试写了一个小web项目,其中涉及到文件上传与下载,虽然网上有很多成熟的框架供使用,但为了学习我还是选择了自己编写相关的代码.当中遇到了很多问题,所以在此这分享完整的上传与下载代码供大家借鉴. ...
- C++ 中mallon动态分配内存大小用法
#include<iostream> using namespace std; int main(){ char *s; int n; cin>>n; s= (char *) ...
- ant学习记录(复制-移动-删除-依赖综合测试)+fileset
<?xml version="1.0"?> <project name="targetStudy" default="mkdir&q ...
- opencv开源库
opencv是开源库 在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib 为什么要CMake,这里我陈述自己的想法,作为一个刚使用opencv库的小白来说,有以下大概 ...
- Mac OSX的开机启动配置
Login Items Mac OSX的当前用户成功登录后启动的程序,该类别的启动项配置文件存放在~/Library/Preferences/com.apple.loginitems.plist,所以 ...
- 在Android开发中,定时器一般有以下3种实现方法
在Android开发中,定时器一般有以下3种实现方法: 原文地址http://www.360doc.com/content/12/0619/13/87000_219180978.shtml 一.采用H ...