69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
struct mooncake{
double store;
double sell;
double price;
}cake[1010];
int main(){
int n;//月饼种类
double D;//市场最大需求量
scanf("%d%lf",&n,&D);
int i;
for(i = 0;i < n;i++){
scanf("%lf",&cake[i].store);//某种月饼库存量
}
for(i = 0;i <n;i++){
scanf("%lf",&cake[i].sell);//某种月饼总售价
cake[i].price = cake[i].sell/cake[i].store;//单价
}
double temp;
if(cake[i].price<cake[i+1].price){//降序排列
temp = cake[i].price;
cake[i].price = cake[i+1].price;
cake[i+1].price = temp;
}
double ans = 0;
for(i = 0;i<n;i++){
if(cake[i].store<=D){
D-=cake[i].store;
ans+=cake[i].sell;
}
else{
ans+=cake[i].price*D;
break;
}
}
printf("%.2f\n",ans);
return 0;
}
#include<stdio.h>
struct mooncake {
double store;
double sell;
double price;
}cake[1010];
int main()
{
int n;//月饼种类
int i, j;
double D;//市场最大需求量
scanf("%d%lf",&n,&D);
for(i = 0;i < n;i++){
scanf("%lf", &cake[i].store);//某种月饼库存量
}
for(i = 0;i <n;i++){
scanf("%lf",&cake[i].sell);//某种月饼总售价
cake[i].price = cake[i].sell/cake[i].store;//单价
}
struct mooncake temp;
for (j = 0; j < n; j++)
for (i = 0; i < n - j - 1; i++)
if (cake[i].price < cake[i+1].price){//降序排列
temp = cake[i];
cake[i] = cake[i+1];
cake[i+1] = temp;
}
double ans = 0;
for(i = 0;i<n;i++){
if(cake[i].store<=D){
D-=cake[i].store;
ans+=cake[i].sell;
}
else{
ans+=cake[i].price*D;
break;
}
}
printf("%.2f\n",ans);
return 0;
}
for(int i = 0; i < n; i++)
if(cake[i].price<cake[i+1].price){//降序排列
temp = cake[i].price;
cake[i].price = cake[i+1].price;
cake[i+1].price = temp;
temp = cake[i].sell;
cake[i].sell = cake[i+1].sell;
cake[i+1].sell = temp;
temp = cake[i].store;
cake[i].store = cake[i+1].store;
cake[i+1].store = temp;
}