Codeforces Round #540 Tanya and Candies 预处理
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 预处理的更多相关文章
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- 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 ...
- 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> ...
- Codeforces Round #540 (Div. 3) B. Tanya and Candies (后缀和)
题意:有\(n\)个数,你可以任意去除某个位置的元素然后得到一个新数组,使得新数组奇数位和偶数的元素相等,现在问你有多少种情况合法. 题解:先求个后缀和,然后遍历,记录奇数和偶数位置的前缀和,删去\( ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...
- 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 ...
- 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 ...
- Codeforces Round #540 (Div. 3)
A链接 讨论一下2a2a2a跟bbb的大小关系即可. #include <set> #include <map> #include <queue> #include ...
- Codeforces Round #540 (Div. 3)--1118C - Palindromic Matrix
https://codeforces.com/contest/1118/problem/C 在查找元素的时候,必须按4,2,1的顺序进行.因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到 ...
随机推荐
- 使用阿里云Python SDK管理ECS安全组
准备工作 本机操作系统:CentOS7 python版本:python2.7.5 还需要准备如下信息: 一个云账号.Access Key ID.Access Key Secret.安全组ID.Regi ...
- Inno Setup脚本
某天夜晚一场狂风暴雨,由于办公室座位旁的窗户没关,笔记本电脑泡了一夜水,无法开机,无奈送修,里面的大量资料也不知道会不会丢失. is的脚本只有重新写了,重新研究了一下检测程序是否正在运行的判断方法,另 ...
- Flink standalone模式作业执行流程
宏观流程如下图: client端 生成StreamGraph env.addSource(new SocketTextStreamFunction(...)) .flatMap(new FlatMap ...
- Redis学习笔记之底层数据结构
1.简单动态字符串(simple dynamic string, SDS) 定义: struct sdshdr { int len;//记录buf中使用的字节数量 int ...
- 20135220谈愈敏Linux Book_1&2
第一章 Linux内核简介 从unix的历史视角来认识Linux内核与Linux操作系统的前世今生. Unix历史 贝尔实验室设计的一个文件系统原型逐渐演化而成Unix,而后Unix操作系统用C语言重 ...
- Linux内核分析第二周学习笔记
linux内核分析第二周学习笔记 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.co ...
- 第三次spring冲刺2
完成了对错题的收集,和做错题的功能,运用了android自带的SQLite数据库.
- C#程序分析
一.程序及问题 阅读下面程序,请回答如下问题: 问题1:这个程序要找的是符合什么条件的数? 问题2:这样的数存在么?符合这一条件的最小的数是什么? 问题3:在电脑上运行这一程序,你估计多长时间才能输出 ...
- C语言入门:01.C语言概述
一.计算机和软件常识 1.计算机运行原理 (1)硬件基本组成:硬盘.内存.CPU (2)个部件之间的运作协调(下图)
- Xcode常见设置
1.设置主题和字体大小