您的位置:首页 > 其它

1070. Mooncake (25)

2013-11-26 23:09 253 查看
1070. Mooncake (25)

#include <iostream>
#include <algorithm>
using namespace std;
class CA
{
public:
enum{N=1000};
struct node
{
double weight,profit;
bool operator < (const node& nd) const
{
return profit > nd.profit;
}
};
int n,m;
double allprofit;
node a
;
void run();
};

void CA::run()
{
allprofit=0;
scanf("%d%d",&n,&m);
int i;
for(i=0;i<n;i++) scanf("%lf",&a[i].weight);
for(i=0;i<n;i++)
{
scanf("%lf",&a[i].profit);
a[i].profit/=a[i].weight;
}
sort(a,a+n);
for(i=0;i<n;i++)
{
if(m>=a[i].weight)
{
allprofit+=a[i].profit*a[i].weight;
m-=a[i].weight;
}
else
{
allprofit+=a[i].profit*m;
break;
}
}
printf("%.2f\n",allprofit);
}

int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Mooncake