#include "OJ.h"
/*
输入: nPapers表示试卷的数目(1≤Papers≤20),nRemain表示剩余的时间(1≤nRemain≤10000),paper[][2]是一个Papers*2的数组,
每一行的两个元素依次为做完这一份试卷所需的时间、做完这份试卷的价值
输出: *pMaxValue为获得的最大价值
返回:
0:异常
1:计算成功返回
*/
int GetMaxValue(int nPapers, int nRemain, int paper[][2], double* pMaxValue)
{
if(nPapers==0 || nRemain==0 || pMaxValue==0 || paper[0]==0)
return 0;
int CostVersusTime[21]={0}; //记录性价比
int Pos[21]={0}; //性价比排序后,原始的位置也排序
for(int i=0;i<nPapers;i++)
{
CostVersusTime[i]=(*(paper[i]+1))/(*(paper[i]));
}
for(int i=0;i<nPapers;i++)
{
Pos[i]=i;
}
//采用冒泡排序,同时也要修改位置信息
for(int i=0;i<nPapers;i++)
{
for(int j=nPapers-1;j>i+1;j--)
{
if(CostVersusTime[j]>CostVersusTime[j-1])
{
int temp=CostVersusTime[j];
CostVersusTime[j]=CostVers
华为OJ Home+work
最新推荐文章于 2021-05-24 12:39:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)