#include <iostream>
#include <set>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int s, res = 0;
cin >> s;
multiset<int> a;
multiset<int> b;
int na;
cin >> na;
while (na--) {
int i;
cin >> i;
a.insert(i);
}
int nb;
cin >> nb;
while (nb--) {
int i;
cin >> i;
b.insert(i);
}
for (multiset<int>::iterator i = a.begin(); i != a.end(); i++) {
multiset<int>::iterator j = b.find(s - *i);
if (j != b.end()) {
for (; j!=b.end(); j++) {
if (*j == s - *i)
res++;
else
break;
}
}
}
cout << res << endl;
}
return 0;
}
[Coursera]算法基础_Week4_动态规划(1)_Q1
最新推荐文章于 2015-12-15 21:23:14 发布