两个元素的和
作者:
小说家
,
2024-12-22 20:09:28
,
所有人可见
,
阅读 2
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
int main() {
int M; cin>>M;
while(M--){
int n, x;
cin >> n >> x;
unordered_map<int, int> ump;
vector<int> a(n);
bool has_find = false;
for (int i = 0; i < n; i++) {
cin >> a[i];
ump[a[i]]++;
}
for (int i = 0; i < n && !has_find; i++) {
int complement = x - a[i];
if (ump.find(complement) != ump.end() && a[i] != complement && ump[complement] > 0) {
has_find = true;
break;
} else if (a[i] == complement && ump[a[i]] > 1) {
has_find = true;
break;
}
ump[a[i]]--;
}
if (has_find) cout << "yes" << endl;
else cout << "no" << endl;
}
return 0;
}