您的位置:首页 > 其它

[Coursera]算法基础_Week4_动态规划(1)_Q1

2015-12-13 15:56 351 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: