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,就找不到 ...
随机推荐
- 浅谈iOS 自动调节文本高度
文字展示是任何GUI开发的一个最常规的编程任务.可能一提及文字我们脑中想到的无非就是 Label 和 Text 这两个关键词,今天我们就谈谈 Label. 无论在 Windows 或者 Web 开发中 ...
- Asp.Net_的传值跟存储值操作
页面传值是学习asp.net初期都会面临的一个问题,总的来说有页面传值.存储对象传值.ajax.类.model.表单等.但是一般来说,常用的较简单有QueryString,Session,Cookie ...
- Android Studio开发实用网站收集
重点 1.Android Studio 调试技巧-断点调试 http://blog.csdn.net/qq_32452623/article/details/53769708 2.android st ...
- 初入Installshield2015
首先我们来认识一下这款软件:这是一款功能强大的软件打包工具,有着许多强大的功能等着我们去发掘,博主也是最近被这个东西搞得有点晕头, 现在就想让读者朋友们更快的接受这个软件. 这个软件需要的破解工具,大 ...
- python基础面试题
函数1def foo(arg,li=[]): li.append(arg) return li list1 = foo(21) list2 = foo(11,[2]) list3 = foo(28) ...
- 原生js实现table的排序
原生js实现table的排序 今天遇到了一个问题就是使用原生js对table标签进行排序 一开始的时候陷入了一个误区就是首先获取table,然后每次比较完大小都会交换children的值,准备到最后吧 ...
- PAT甲题题解-1127. ZigZagging on a Tree (30)-中序、后序建树
根据中序遍历和前序遍历确定一棵二叉树,然后按“层次遍历”序列输出.输出规则:除根节点外,接下来每层的节点输出顺序是:先从左到右,再从右到左,交替输出 #include <iostream> ...
- Scrum立会报告+燃尽图(十二月十一日总第四十二次):贡献分配和收集用户报告
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2484 项目地址:https://git.coding.net/zhang ...
- M1阶段事后分析
M1阶段的开发结束了,在周四的课上我们组也进行了alpha阶段的汇报.我们的努力得到了应有的回报,下面我们将针对M1阶段产生的一些问题进行分析和反思. 一.设想和目标 1.我们的app更像是一款针对北 ...
- 【读书笔记】Linux内核设计与实现(第一章&第二章)
http://pan.baidu.com/s/1hqYAZNQ OneNote做的笔记没法儿带着格式一起导进来.所以上传到百度云,麻烦老师下载一下了. 下次不再用OneNote.