码迷,mamicode.com
首页 > 其他好文 > 详细

CF988 C. Equal Sums

时间:2018-06-07 19:38:55      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:cpp   set   并且   cout   ret   com   make   ref   pre   

题目链接: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;
}

CF988 C. Equal Sums

标签:cpp   set   并且   cout   ret   com   make   ref   pre   

原文地址:https://www.cnblogs.com/goxy/p/9152021.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!