1 条题解

  • 0
    @ 2026-4-7 20:32:51

    题目中的等式等价于:

    $$2 \cdot \sum _{i = 1} ^x a_i = \sum _{i = 1} ^n a_i$$

    等式右边是定值,左边可以用一次前缀和 O(n)O(n) 算出所有 xx 值对应的计算结果,逐个判断即可。

    #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 = -1;
    		for (int i = 0; i <= n; i++)
    			if (2 * t[i] == s)
    			{
    				a = i;
    				break;
    			}
    		cout << a << endl;
    	}
    	return 0;
    }
    
    • 1

    [2026 February TFOJ Normal Round] Seesaw Management 1

    信息

    ID
    249
    时间
    1000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    2
    已通过
    2
    上传者