当前位置:网站首页>1020 moon cake
1020 moon cake
2022-07-21 20:27:00 【Hide tears with soil】
1020 The moon cake
Moon cake is a kind of traditional food that Chinese people eat during the Mid Autumn Festival , There are many different flavors of moon cakes in different regions . Now, the inventory of all kinds of mooncakes is given 、 Total selling price 、 And the biggest demand in the market , Please calculate the maximum profit you can get .
Be careful : Allow to take out part of the inventory when selling . The example shows this : If we have 3 Mooncakes , The inventory is 18、15、10 Ten thousand tons of , The total selling price is 75、72、45 One hundred million yuan . If the market's maximum demand is only 20 Ten thousand tons of , Then our biggest revenue strategy should be to sell all 15 Ten thousand tons 2 Mooncakes 、 as well as 5 Ten thousand tons 3 Mooncakes , get 72 + 45/2 = 94.5( One hundred million yuan ).
Input format :
Each input contains a test case . Each test case shall be provided with no more than one 1000 The positive integer N Number of moon cakes 、 And not more than 500( In 10000 tons ) The positive integer D Represents the maximum market demand . The next line shows N A positive number indicates the stock of each kind of moon cake ( In 10000 tons ); The last line gives N A positive number indicates the total selling price of each kind of moon cake ( In 100 million yuan ). Numbers are separated by spaces .
Output format :
For each group of test cases , Output maximum revenue in one line , In hundred million yuan and accurate to the decimal point 2 position .
sample input :
3 20
18 15 10
75 72 45
sample output :
94.50
I wrote it in structure , This question , Main comparison unit price , The higher the unit price , The more you sell , The more profits
Code :
#include<stdio.h>
#include<math.h>
struct
{
float c,j;
} d[1000],temp;
int main()
{
float n,m;
scanf("%f%f",&n,&m);
int i,k;
float a[1000],b[1000],l;
l=0;
for(i=0; i<n; i++)
{
scanf("%f",&a[i]);
}
for(i=0; i<n; i++)
{
scanf("%f",&b[i]);
}
for(k=0; k<n; k++)
{
d[k].c=b[k]/a[k];
d[k].j=a[k];
}
for(i=0; i<n-1; i++)
{
for(k=0; k<n-1-i; k++)
{
if(d[k].c<d[k+1].c)
{
temp=d[k];
d[k]=d[k+1];
d[k+1]=temp;
}
}
}
for(i=0; i<n; i++)
{
if(d[i].j<=m)
{
l=l+d[i].c*d[i].j;
}
if(d[i].j>m)
{
l=l+d[i].c*m;
break;
}
m=m-d[i].j;
if(m==0)break;
}
printf("%.2f",l);
return 0;
}
边栏推荐
猜你喜欢
[PCB] modify the default settings for items such as (via) (text string) (wiring linear dimension) in Altium designer
Owncloud 9.0 better cross server sharing and scalability
基于OpenCV和Dlib+fr的人脸检测以及基于Dlib人脸对齐
合泰HT32 & 淘晶驰TJC--T0串口屏学习笔记
小游戏类项目 —— 五子棋游戏
3. Build the basic model of paddlepaddle from scratch (compare with keras and pytorch)
Hetai 32 onenet WiFi module - Hetai MCU data cloud through mqtt protocol (I)
Pytorch foundation module and Practice
1027打印沙漏
5. Paddlepaddle 10 lines of code deep learning image classification (cifar)
随机推荐
[PCB] production document sorting and output of circuit board drawing notes -- drawing board notes
使用MATLAB GUI 设计工具开发小项目
1024 科学计数法
OLED (classic 0.96 inch) -4spi--ssd1306 control principle (including common chip _oled routines)
深度理解指针(冒泡排序模拟实现qsort,函数指针实现回调函数)
合泰HT32--淘晶驰TJC--T0串口屏学习笔记(二)
[record] the operation of optisystem is stuck, and it is unable to click to close, input variable values and other solutions
Owncloud 9.0 better cross server sharing and scalability
记录关于写程序的一些个小芝士~【持续更~】
1009说反话
Examples of enumeration
让代码解决《线性代数》系列 - 求多项式的最大公因式
[3D modeling] SolidWorks 3D modeling and prusaslicer slice printing learning notes
Checkpoint in the deep learning source code project
25.【判断是否是素数的方法】
Doing questions leads to the understanding of getchar ()
namespace 命名空间
Pre training and fine tuning of Google Bert model for beginners
三子棋
Account class