#include
#include
using namespace std;
Int coinHarsh [510]={0};
Int COINS [100010].
Int main () {
Int N, M;
int temp;
Bool solute=false;
The scanf (" % d % d ", & amp; N, & amp; M);
for (int i=0; i
COINS [I]=temp;
CoinHarsh [temp] + +;
}
Sort (COINS, COINS + N);
for (int i=0; i
Int b=M - a;
If (a==b & amp; & CoinHarsh [a] & gt; 1) {
Printf (" % d % d ", a, b);
Solute=true;
break;
}
If (coinHarsh [b] & gt; 0 & amp; & CoinHarsh [a] & gt; 0 {
Printf (" % d % d ", a, b);
Solute=true;
break;
}
}
if (! Solute) {
Printf (" No Solution ");
}
return 0;
}
CodePudding user response:
The hope can help youhttps://blog.csdn.net/qq_36491095/article/details/104451454Your problem in the input when a m/2 error output
CodePudding user response:
Although it could be 10 ^ 5 COINS, but no more than 500 COINS denominations areLoad the COINS, synchronous record different denominations of numerical array of the number of COINS to coinHarsh
And then in the midst of coinHarsh find two is not zero, and is M can not yet
COINS array also sort what is the point? White waste of time, time out your part right?
I don't see COINS array existence, loading process of statistical results directly to coinHarsh ok
For (int index=1; Index<=500; Index++) {//not face value is 0, the cycle starts at 1
If (index * 2 & gt; M) {//more than 2 M/a, haven't found conform to the requirements of the coin, there can be no solution to the
No output, exit the program
}
If (0==coinHarsh [index]) continue;//don't have the denomination COINS
If (M==index * 2 & amp; & CoinHarsh [index] & gt; 1) {//two same denomination COINS to
Output the answer
}
If (coinHarsh [M - index] & gt; 0) {//find out
Output index and M - index
End program
}
}