第1关:装载问题 (FIFO 优先队列法)
#include "Queue.h"
#include <iostream>
using namespace std;
int N = 0;
template<class Type>
class QNode
{
public:
QNode *parent;
bool LChild;
Type weight;
};
template<class Type>
void EnQueue(Queue<QNode<Type>*>&Q,Type wt,int i,int n,Type bestw,QNode<Type>*E,QNode<Type> *&bestE,int bestx[],bool ch);
template<class Type>
Type MaxLoading(Type w[],Type c,int n,int bestx[]);
int main()
{
float c = 0;
float w[100] = {
0};
int x[100];
float bestw;
cin>>N;
cin >>c;
for(int i=1; i<=N; i++)
{
cin>>w[i];
}
cout<<"Ship load:"<<c<<endl;
cout<<"The weight of the goods to be loaded is:"<<endl;
for(int i=1; i<=N; i++)
{
cout<<w[i]<<" ";
}
cout<<endl;
bestw = MaxLoading(w,c,N,x);
cout<<"Result:"<<endl;
for(int i=1; i<=N; i++)
{
cout<<x[i]<<" ";
}
cout<<endl;
cout<<"The optimal loading weight is:"<<bestw<<endl;
return 0;
}
template<class Type>
void