First, the technical summary
- First, a little at first glance does not understand the subject, title roughly means Xiaoming there are many coins of different denominations, but now he wants to get a new business here face value,
and the business has a provision, a new coin must you two coins add up to the nominal value to change, that there is a first problem arises, that is, combinations of two will produce a variety of new coins
which here takes the minimum, then the output of the small front face value. The second problem is the same two coins may occur.
- So, I started using an array of type bool, int whether or not to adopt the type of look the same coin denomination may appear twice. So there is a test point was not the first time through the submission.
After correcting the problem is solved.
Second, the reference code
#include<iostream>
using namespace std;
bool hashTable[1000010] = {0};
int main(){
int N,M;
cin >> N >> M;
int num;//用于记录每次输入的硬币面值
for(int i = 0; i < N; i++){
cin >> num;
hashTable[num] = true;
}
int flag = 0;//用于标记是否有解决方案
for(int i = 1; i < M; i++){
if(hashTable[i] == true){
if(hashTable[M-i] == true && M-i != i){
cout << i << " " << M-i;
flag = 1;
break;
}
}
}
if(flag == 0) cout << "No Solution";
return 0;
}