CF988 C. Equal Sums

题目链接:http://codeforces.com/problemset/problem/988/C
题意:给n个数列,若存在两个不一样的数列,两者各去掉一项后值一样那么输出YES,并且输出这两个数列的编号和对应项的序号
题解:使用map存储,键:每一个数列的和除去每一项,值:对应的编号和序号队(使用pair)

#include<iostream>
#include<map>
#include<vector>
using namespace std;
map<int,pair<int,int> >m;
vector<int>arr;
int main()
{
    int k;
    cin>>k;
    for(int i = 0; i < k; i ++){
        int n,tmp,sum = 0;
        cin>>n;
        for(int j = 0; j < n; j ++){
            cin>>tmp;
            arr.push_back(tmp);
            sum += tmp;
        }
        for(int j= 0; j < n; j ++){
            if(m.find(sum - arr[j]) == m.end()){
                m[sum-arr[j]] = make_pair(i + 1, j + 1);
            }
            else{
                if((i + 1) != m[sum-arr[j]].first){
                    cout<<"YES"<<endl;
                    cout<<m[sum-arr[j]].first<<" "<<m[sum-arr[j]].second<<endl;
                    cout<<i + 1<<" "<<j + 1;
                    return 0;
                }
            }
        }
        arr.clear();

    }
    cout<<"NO"<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/asakuras/p/9152021.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值