首页 > 学院 > 开发设计 > 正文

PAT 1070

2019-11-08 00:50:21
字体:
来源:转载
供稿:网友
#include<cstdio>#include<stdlib.h>#include<cstring>#include<algorithm>using namespace std;struct mooncake{	double store;	double sell;	double PRice;}cake[1010];bool cmp(mooncake x,mooncake y){	return x.price>y.price;}int main(){		int n;	double d;	double p=0;	scanf("%d%lf",&n,&d);	for(int i=0;i<n;i++)	{		scanf("%lf",&cake[i].store);	}	for(int i=0;i<n;i++)	{		scanf("%lf",&cake[i].sell);		cake[i].price=cake[i].sell/cake[i].store;	}	sort(cake,cake+n,cmp);	for(int i=0;i<n;i++)	{		if(cake[i].store<=d)		{			d-=cake[i].store;			p+=cake[i].sell;		}		else		{			p+=d*cake[i].price;			break;		}	}	printf("%.2f",p);	system("pause");	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表