Codeforces C. Stripe (Round #18 Div.2 Only) (前缀和水题)

传送门

题意: 看了半天没看懂那个平方数的意思,理解就是求有几种方法可以一刀将数组切成两半,使得左右两半的和相等。
在这里插入图片描述
思路: 利用前缀和就很容易求得左右两段分别的和。

代码实现:

#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
using namespace std;
const int  N = 2e5 + 5;

int n, a[N], ans;

signed main()
{
    
    
    IOS;

    cin >> n;
    for(int i = 1; i <= n; i ++){
    
    
        int x; cin >> x;
        a[i] = a[i-1]+x;
    }
    for(int i = 1; i < n; i ++)
        if(a[i] == a[n]-a[i]) ans ++;
    cout << ans << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Satur9/article/details/109302658
今日推荐