Home > Back-end >  At least a coin problem solving
At least a coin problem solving

Time:04-14



O great god see where there is a problem? thank you

CodePudding user response:

Suggest the original poster don't post pictures, it is more convenient to post code, reference:
 # include 
#include

using namespace std;

Typedef struct {
Int T;//value
Int C;//number of COINS
}Node;

Bool compare (Node & amp; A, the Node & amp; B)
{
Return a.T & lt; B.T.
}

Int the seek (Node * p, int n, int m)
{
Int q=m;
int t;
Int sum=0;
int i;
For (I=n - 1; I>=0; I -)//for (I=n; I>=0; I -) array subscript crossing the line
{
T=(q/p [I] t);
If (t> P [I]. C) t=p [I] C.//must not exceed the holding the current number of COINS
Q - t * p=[I] t;
The sum +=t;
If (q==0) break;
}
If (q==0)
{
return sum;
} else {
return -1;
}
}

Int main ()
{
int n;
Cin> n;
//the Node a, [n].
A=new Node Node * [n].
int i;
for(i=0; i{
Cin> A [I] T> A [I] C;
}
Int m;
Cin> m;

Sort (a, a + n, compare);
Int p=the seek (a, n, m);
If (p> 0)
{
Cout} else {
Cout<& lt;" 1 ";
}

return 0;
}
  • Related