码迷,mamicode.com
首页 > 其他好文 > 详细

L2-003. 月饼

时间:2017-08-14 18:59:47      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:stream   int   ace   opera   std   i++   space   operator   main   

 

 

 

 

#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. 月饼

标签:stream   int   ace   opera   std   i++   space   operator   main   

原文地址:http://www.cnblogs.com/1915884031A-qqcom/p/7359460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!