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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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;
}