A1070
作者:互联网
给出总价和需求量,求最大收益。
思路:求单价最高的,排序。
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 struct mooncake{ 5 double store;//存货 6 double sell;//总价 7 double price;//单价 8 }cake[1010]; 9 bool cmp(mooncake a,mooncake b){ 10 return a.price>b.price; 11 } 12 int main(){ 13 int n; 14 double d;//需求总量 15 scanf("%d %lf",&n,&d); 16 for(int i=0;i<n;i++){ 17 scanf("%lf",&cake[i].store); 18 } 19 for(int i=0;i<n;i++){ 20 scanf("%lf",&cake[i].sell); 21 cake[i].price=cake[i].sell/cake[i].store; 22 } 23 sort(cake,cake+n,cmp); 24 double ans=0;//收益 25 for(int i=0;i<n;i++){ 26 if(cake[i].store<=d){ 27 d-=cake[i].store; 28 ans+=cake[i].sell; 29 } 30 else{ 31 ans+=cake[i].price*d; 32 break; 33 } 34 } 35 printf("%.2f\n", ans); 36 return 0; 37 }
标签:int,double,price,mooncake,A1070,include,单价 来源: https://www.cnblogs.com/Lynn-2019/p/10388770.html