招聘网站数据分析要怎么做,wordpress地图插件,中国网站建设公司,做绿植o2o网站怎么样有一批集装箱要装上一艘载重量为c的轮船。其中集装箱i的重量为Wi。最优装载问题要求确定在装载体积不受限制的情况下#xff0c;将尽可能多的集装箱装上轮船。
#includeiostream
#includealgorithm
#includecstring
using namespace std;typedef str…有一批集装箱要装上一艘载重量为c的轮船。其中集装箱i的重量为Wi。最优装载问题要求确定在装载体积不受限制的情况下将尽可能多的集装箱装上轮船。
#includeiostream
#includealgorithm
#includecstring
using namespace std;typedef struct Node
{int number;//序列中的第几个 int weight;//序列的重量
}node;
bool cmp(node x,node y)
{if(x.weighty.weight)return true;elsereturn false;}
void Loading(int *result,int *weight,int capacity,int n)
{Node node[n1];for(int i1;in;i){node[i].numberi;node[i].weightweight[i];}sort(node1,noden1,cmp);cout货物按重量排好序为; for(int i1;in;i){coutnode[i].weight ;weight[i]node[i].weight;}coutendl;for(int i1;in;i){result[i]0;}int pre1;int ccapacity;for(int i1;in;i){if(weight[i]c){result[i]1;cc-weight[i];}else{break;}}}
int main()
{cout输入集装箱的数量;int n;cinn;cout输入轮船所能承担的最大重量;int capacity;cincapacity;cout输入集装箱的重量序列;int weight[n1];for(int i1;in;i){cinweight[i];}int result[n1];Loading(result,weight,capacity,n);for(int i1;in;i){coutresult[i] ;}}