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 ;
}