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

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

 #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. stderr: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

    错误提示: (1). stderr: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer direc ...

  2. PetaPoco轻量级ORM框架 - 对Database类的进行扩展,可以返回Table格式数据

    一.有时我们需要将常用的功能添加到PetaPoco中的Database类中 实现方式有2种,以下以查询字段为例 1.通过扩展方式实现,此方式不改变被调用(Database)类名(只能增加方法) pub ...

  3. 021.2 IO流——字节输出流

    内容:流的分类,文件写入(字节输出流),异常处理,获取一个文件夹下的特定文件集合 字节流的抽象基类:InputStream,OutputStream字符流的抽象基类:Reader,Writer由这四个 ...

  4. Cinder组件解析

    1  Cinder架构图 Cinder是在虚拟机和具体存储设备之间引入了一层“逻辑存储卷”的抽象,Cinder本身并不是一种存储技术,只是提供一个中间的抽象层,Cinder通过调用不同存储后端类型的驱 ...

  5. python之使用__future__

    Python的新版本会引入一些新的功能特性,但一般一部分的新功能可以在旧版本上测试,测试成功再移植到新的版本上,旧版本可以通过导入__future__模块的某些功能,测试新版本的新功能.(注意:fut ...

  6. SpringMVC DELETE,PUT请求报错 添加支持Http的DELETE、PUT请求

    SpringMVC删除与修改操作需要用DELETE,PUT请求方式提交. 但要知道浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持. spring3.0添加了 ...

  7. selenium断言的分类

    操作(action).辅助(accessors)和断言(assertion): 操作action: 模拟用户与 Web 应用程序的交互. 辅助accessors: 这是辅助工具.用于检查应用程序的状态 ...

  8. php json格式化输出

    1.json格式是适用于多种语言的数据格式,通用性高 2.在php中将array格式的数据转化为json格式 3.默认情况下转化后的json格式为一个串,需要将这个串格式化成相应的样式输出 主要的函数 ...

  9. Jmeter服务器监控插件使用

    Jmeter服务器监控插件使用 Jmeter-Plugins支持CPU.Memory.Swap.Disk和Network的监控,在测试过程中更加方便进行结果收集和统计分析. 一.准备工作: 1.下载J ...

  10. HDU 1158(非常好的锻炼DP思维的题目,非常经典)

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1158 Employment Planning Time Limit: 2000/1000 MS (Java/Oth ...