L2-003. 月饼

Posted diamondDemand

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了L2-003. 月饼相关的知识,希望对你有一定的参考价值。

 

 

 

 

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct mooncake{
float price;
float reserve;
float allPrice;
bool operator < (const mooncake &a) const
{
return price > a.price;
}
}nowMoon[1001];   //i know how to use the struct
int main()
{
int n, d;
cin >> n >> d;
for(int i=0; i<n; i++)
cin >> nowMoon[i].reserve;
for(int i=0; i<n; i++)
{
cin >> nowMoon[i].allPrice;
nowMoon[i].price = nowMoon[i].allPrice/nowMoon[i].reserve;
}
sort(nowMoon, nowMoon+n);
int i=0;
float biggestIncome = 0;
while(d>0&&i<n)
{
if(d>=nowMoon[i].reserve)
{
biggestIncome = biggestIncome + nowMoon[i].allPrice;
d = d - nowMoon[i].reserve;
i++;
}
else
{
biggestIncome = biggestIncome + d * nowMoon[i].price;
break;
}
}
printf("%0.2f", biggestIncome);
return 0;
}  //so easy, i think you can understand without interpretation

以上是关于L2-003. 月饼的主要内容,如果未能解决你的问题,请参考以下文章

L2-003. 月饼

天梯杯 L2-003. 月饼

L2-003 月饼 python实现

L2-003 月饼(贪心)

L2-003. 月饼

L2-003月饼