标签: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
标签:stream int ace opera std i++ space operator main
原文地址:http://www.cnblogs.com/1915884031A-qqcom/p/7359460.html