给出总价和需求量,求最大收益。

思路:求单价最高的,排序。

 #include<cstdio>
#include<algorithm>
using namespace std;
struct mooncake{
double store;//存货
double sell;//总价
double price;//单价
}cake[];
bool cmp(mooncake a,mooncake b){
return a.price>b.price;
}
int main(){
int n;
double d;//需求总量
scanf("%d %lf",&n,&d);
for(int i=;i<n;i++){
scanf("%lf",&cake[i].store);
}
for(int i=;i<n;i++){
scanf("%lf",&cake[i].sell);
cake[i].price=cake[i].sell/cake[i].store;
}
sort(cake,cake+n,cmp);
double ans=;//收益
for(int i=;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 ;
}

A1070的更多相关文章

  1. A1070. Mooncake

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...

  2. A1070 Mooncake (25 分)

    一.参考代码 #include<cstdio> #include<algorithm> #include<iostream> using namespace std ...

  3. PAT甲级——A1070 Mooncake

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...

  4. 1070 Mooncake (25 分)

    1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn ...

  5. PAT_A1070#Mooncake

    Source: PAT A1070 Mooncake (25 分) Description: Mooncake is a Chinese bakery product traditionally ea ...

  6. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. cmd命令提示符大全(干货)

    cmd是command的缩写.即命令提示符(CMD),是在OS / 2 , Windows CE与Windows NT平台为基础的操作系统(包括Windows 2000和XP中, Vista中,和Se ...

  2. IGraphicsContainer->AddElement函数

    纠结中...... IGraphicsContainer.AddElement函数应该是比较简单的,可能无论添加什么要素,就是无法显示出结果出来. 难道添加元素前是有什么需要设置的?或是其它一些原因? ...

  3. ZT 打工者买彩票中1000万 5年后变逃犯身上剩80元

    打工者买彩票中1000万 5年后变逃犯身上剩80元   2014-01-07 08:22 来源:都市快报 我有话说 挥霍—— 从800万到80元 在湖南永州零陵区富家桥镇茶叶湾村,陈某是不折不扣的名人 ...

  4. [BZOJ 2730][HNOI 2012] 矿场搭建

    2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2113  Solved: 979[Submit][Statu ...

  5. aclocal: error: aclocal: file '/usr/local/share/aclocal/wxwin.m4' does not exist

    1. 查找wxwin.m4文件 mdfind -name wxwin.m4 2. 删除/usr/local/share/aclocal/wxwin.m4,建立软连接 cd /usr/local/sha ...

  6. IOS XMPP(即时通讯的框架)

    #import "AppDelegate.h" #import "XMPPFramework.h" /* * 在AppDelegate实现登录 1. 初始化XM ...

  7. Apache Jemeter 开发插件

    为什么选择使用JMeter 当被问到这个问题的时候,也许你会在脑海里产生很多的理由,比如: Apache基金会下的开源项目,没有版权问题: 为数不多的还在持续更新的开源性能自动化测试工具: 支持协议丰 ...

  8. Spark SQL on Yarn-Cluster

    Spark SQL 或者Hive SQL在yarn-client模式下运行正常,但是在yarn-cluster模式下总是报 status failed错误, 需要把$SPARK_HOME/lib/sp ...

  9. iOS绘图事务的运行验证

    结合WWDC,以我们的call stack为例,来说明这四个过程分别大概都做了什么. layout过程 从上面layout的过程可以看出,其所做的主要任务就是将图层调用代理(也就是视图)实现整个视图层 ...

  10. iOS的图片:解码(CPU)与内存(缓存)

    图片的数据:资源数据(地址).原始数据(Data).显示数据(解码后的数据) 解压图片 - PNG或者JPEG压缩之后的图片文件会比同质量的位图小得多.但是在图片绘制到屏幕上之前,必须把它扩展成完整的 ...