|hash 雜湊|1048 Find Coins (25分)
阿新 • • 發佈:2021-01-21
技術標籤:PAT甲
//TLE
//20/25
// #include <iostream>
// #include <vector>
// #include <algorithm>
// using namespace std;
// vector<int>v;
// vector<int>ans;
// int main() {
// int n, m;
// cin >> n >> m;
// for (int i = 0; i < n; i++) {
// int value;
// cin >> value;
// v.push_back(value);
// }
// for (int i = 0; i < v.size()-1; i++) {
// for (int j = i + 1; j < v.size(); j++) {
// if (v[i] + v[j] == m) {
// ans.push_back(min(v[i], v[j]));
// }
// }
// }
// if (ans.size() == 0)
// cout << "No Solution";
// else {
// sort(ans.begin(), ans.end());
// cout << ans[0]<<" "<<m - ans[0];
// }
// return 0;
// }
#include <iostream>
#include <algorithm>
using namespace std;
int const MAXN = 1010;
int hashTable[MAXN] = { 0 };
int main() {
int n,m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int value;
cin >> value;
hashTable[value]++;
}
for (int i = 0; i < MAXN; i++) {
if (hashTable[i] != 0 && hashTable[m-i] != 0) {
if (i == m - i && hashTable[i]<=1) {
continue;
}
cout << i << " " << m - i;
return 0;
}
}
cout <<"No Solution";
return 0;
}