Codeforces Round #540 (Div. 3) B. Tanya and Candies

直接维护第i个数为止,前面的奇数的数的累加和 和偶数的数的累加和

然后枚举判断这个数拿不拿,那的话这个数之后的奇数和偶数的累加和反转

#include
#define ll  long long
using namespace std;
const int MAXN = 2e5 + 10;
int cs[MAXN];
ll ji[MAXN], ou[MAXN];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++)
    {
        scanf("%d", &cs[i]);
    }
    for(int i = 1; i <= n; i ++)
    {
        if(i % 2 == 1)
            ji[i] = ji[i - 1] + cs[i], ou[i] = ou[i - 1];
        else
            ji[i] = ji[i - 1], ou[i] = ou[i - 1] + cs[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; i ++)
    {
        ll t1 = ji[i - 1], t2 = ou[i - 1];
        ll t3 = ji[n] - ji[i], t4 = ou[n] - ou[i];
        if(t1 + t4 == t2 + t3)
            ans ++;
    }
    printf("%d", ans);
    return 0;
}

 

你可能感兴趣的:(Codeforces Round #540 (Div. 3) B. Tanya and Candies)