http://codeforces.com/contest/1118/problem/B

题目大意,给你一个序列,删去一个数值之后,要求剩下序列奇数和偶数的和相同,问有多少种删法。

思路:预处理奇数和偶数和即可

(算法能力康复性训练中......)

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n") using namespace std;
const int maxn = 2e5 + ;
int a[maxn];
//表示到当前的偶数或奇数和
int odd1[maxn], even1[maxn];//前往后
int n; int main(){
cin >> n;
for (int i = ; i <= n ;i++){
scanf("%d", a + i);
}
int sum = ;
for (int i = ; i <= n; i++){
even1[i] = even1[i-];
odd1[i] = odd1[i-];
sum += a[i];
if (i % == ) odd1[i] += a[i];
else even1[i] += a[i];
}
int ans = ;
for (int i = ; i <= n; i++){
if (i % == ){
int odd = even1[n] - even1[i] + odd1[i] - a[i];
int even = sum - a[i] - odd;
if (odd == even) ans++;
}
else {
int odd = odd1[i] + even1[n] - even1[i];
int even = sum - odd - a[i];
if (odd == even) ans++;
}
}
printf("%d\n", ans);
return ;
}

Codeforces Round #540 Tanya and Candies 预处理的更多相关文章

  1. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  2. Codeforces Round #540 (Div. 3)--1118B - Tanya and Candies(easy TL!)

    Tanya has nn candies numbered from 11 to nn. The ii-th candy has the weight aiai. She plans to eat e ...

  3. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  4. Codeforces Round #540 (Div. 3) B. Tanya and Candies (后缀和)

    题意:有\(n\)个数,你可以任意去除某个位置的元素然后得到一个新数组,使得新数组奇数位和偶数的元素相等,现在问你有多少种情况合法. 题解:先求个后缀和,然后遍历,记录奇数和偶数位置的前缀和,删去\( ...

  5. Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化

    链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...

  6. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  7. Codeforces Round #355 (Div. 2) C 预处理

    C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #540 (Div. 3)

    A链接 讨论一下2a2a2a跟bbb的大小关系即可. #include <set> #include <map> #include <queue> #include ...

  9. Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix

    https://codeforces.com/contest/1118/problem/C 在查找元素的时候,必须按4,2,1的顺序进行.因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到 ...

随机推荐

  1. 获取【酷我音乐】歌曲URL地址

    非原创 酷我中的歌曲的页面地址通常是:www.kuwo.cn/yinyue/6181801,末尾的一串数字是这首歌曲的编号id. 我们只须在 http://player.kuwo.cn/webmusi ...

  2. Kubernetes学习-基础架构

    kubectl是一个Kubernetes提供的客户端工具,是用于操作kubernetes集群的命令行接口,通过利用kubectl的各种命令可以实现各种功能,是在使用kubernetes中非常常用的工具 ...

  3. float和position的使用

    http://blog.csdn.net/yaodebian/article/details/58621183

  4. python引入pytesseract报错:ValueError: Attempted relative import in non-package

    http://blog.csdn.net/yifengfuxue/article/details/79015651

  5. 20181023-3 每周例行报告(添加PSP)

    此作业要求:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2100] 一.本周PSP表格 类型 任务 开始时间 结束时间 中断时间 净时 ...

  6. Alpha版本项目展示要求(加入模板)

    Alpha版本展示的时间暂定为11月17日课上,提前到13:00开始.如有变动,另行通知. Alpha版本项目展示要求如下: 不得使用PPT,展示所用的资料必须发表在博客上. 现场演示你们发布的软件. ...

  7. Web项目--------原Oracle数据库的项目同时兼容MySql

    原Oracle数据库的项目同时兼容MySql步骤: (一)修改资源配置文件applicationContext-dataSource.xml的数据库连接 Oracle数据库中加上from dual的原 ...

  8. 关于Win10系统下VC2013安装Unit test出现问题的解决办法

    话不多说,先上图~~~ 很多同学在Vs2013安装Unit test组件时会弹出这样的对话框,极其极其让人崩溃. 当我看到这个对话框时,首先中规中矩的去官网下载.NET(但是我怎么可能没有!游戏环境包 ...

  9. sqlserver附加数据库时,无法打开物理文件 "xx.mdf"。操作系统错误 5:"5

    sqlserver在附加数据库时,提示无法打开物理文件 "xx.mdf".操作系统错误 5:"5 此时可能你是用window验证方式登陆数据库的? 如果是这样,断开连接, ...

  10. Android map转json格式,附上Jackson包下载地址,导入过程

    android中的map转json,需要下载jackson包,下载地址: http://www.java2s.com/Code/Jar/j/Downloadjacksonall199jar.htm 下 ...