zoukankan      html  css  js  c++  java
  • 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
    ")
    
    using namespace std;
    const int maxn = 2e5 + 5;
    int a[maxn];
    //表示到当前的偶数或奇数和
    int odd1[maxn], even1[maxn];//前往后
    int n;
    
    int main(){
        cin >> n;
        for (int i = 1; i <= n ;i++){
            scanf("%d", a + i);
        }
        int sum = 0;
        for (int i = 1; i <= n; i++){
            even1[i] = even1[i-1];
            odd1[i] = odd1[i-1];
            sum += a[i];
            if (i % 2 == 1) odd1[i] += a[i];
            else even1[i] += a[i];
        }
        int ans = 0;
        for (int i = 1; i <= n; i++){
            if (i % 2 == 1){
                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
    ", ans);
        return 0;
    }
    View Code
  • 相关阅读:
    spoj705
    bzoj2440
    spoj220
    bzoj2301
    hdu1695
    poj3294
    hdu3518
    poj3693
    函数
    样式
  • 原文地址:https://www.cnblogs.com/heimao5027/p/10440041.html
Copyright © 2011-2022 走看看