C. Equal Sums

题目链接

Codeforces Round #486 (Div. 3)--C. Equal Sums

题解

基础题,题意大概是给定一些数字序列,找出各删去一个数后和相等的两个序列。
找出每个序列删去每个数字后可能的值并记录序列与删去的数字,如果发现两个序列删去某一个数之后相等输出即可。

代码

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <string.h>
using namespace std;
struct which
{
    int i, x;
};
int n, k,sum;
int a[200005];
map<int, bool>q1;
map<int, which>q2;

int main() {
    cin >> k ;
    for (int i = 1; i <= k; i++) {
        cin >> n;
        sum = 0;
        for (int j = 1; j <= n; j++) {
            cin >> a[j];
            sum += a[j];
        }
        for (int j = 1; j <= n; j++) {
            if (q1[sum - a[j]] == false) {
                q1[sum - a[j]] = true;
                q2[sum - a[j]] = { i,j };
            }
            else if (i!=q2[sum-a[j]].i){
                cout << "YES" << endl;
                cout << q2[sum - a[j]].i << ' ' << q2[sum - a[j]].x<<endl;
                cout << i << ' ' << j;
                return 0;
            }
        }
    }
    cout << "NO";
}

标签: implementation, sortings

添加新评论