1 条题解
-
0
题目中的等式等价于:
$$2 \cdot \sum _{i = 1} ^x a_i = \sum _{i = 1} ^n a_i$$等式右边是定值,左边可以用一次前缀和 算出所有 值对应的计算结果,逐个判断即可。
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 12; long long t[N]; int main() { long long n, x, s = 0, a = 0; while (cin >> n) { s = 0; for (int i = 1; i <= n; i++) { cin >> x; s += x; t[i] = s; } a = 0; for (int i = 0; i <= n; i++) if (2 * t[i] == s) a++; cout << a << endl; } return 0; }
- 1
信息
- ID
- 205
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 2
- 标签
- 递交数
- 6
- 已通过
- 4
- 上传者