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

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

 #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. 简说mvc路由

    首先我们通过在Global.asax中的Application_Start将路由信息注册到RouteTable的Routes静态属性中.如下代码所示: public class RouteTable ...

  2. Java学习---连接数据库操作

    Java连接Oracle数据库 package com.ftl.mysql; import java.sql.Connection; import java.sql.DriverManager; im ...

  3. css中的圣杯布局和双飞翼布局

    圣杯布局 布局要求: 三列布局,中间自适应,两边定宽 中间栏要在浏览器优先渲染 允许任意列的高度最高 用最简单的CSS.最少的HACK语句 解释说明: 1.min-width:700px是为了当页面缩 ...

  4. winform中webBrowser模拟网页操作中遇到的问题

    我们通过网页上传一些特殊数据的时候,由于必填项众多,数量量大的时候,会发现工作相当繁琐,前段时间做了一个winform内嵌webBrowser模拟网页上传文档的小工具,发现了许多问题,总结一下: 先说 ...

  5. GPL & Apache License

    Copyleft[编辑] GPL不会授予许可证接受人无限的权利.再发行权的授予需要许可证接受人开放软件的源代码,及所有修改.且复制件.修改版本,都必须以GPL为许可证. 这些要求就是copyleft, ...

  6. java冒泡排序-选择排序-插入排序-使用API中文文档直接调用函数

    import java.util.Arrays; public class ArrayDemo2_3 { public static void main(String []args) { //---- ...

  7. 没有什么问题是sudo rm -rf /* 解决不了的

    没有什么问题是sudo rm -rf /* 解决不了的. . . . . . . 如果有的话,赶紧跑.

  8. elk6.*版本搭建连接 比较好一点的

    https://www.cnblogs.com/harvey2017/p/8922164.html

  9. Mybatis 插件

    在spring整合mybatis的配置中, 插件注册 <property name="plugins"> <!-- 配置SqlSessionFactoryBean ...

  10. Dubbo实践(六)Spring加载Bean流程

    根据上一小节对于spring扩展schema的介绍,大概可以猜到dubbo中相关的内容是如何实现的. 再来回顾Dubbo实践(一)中定义的dubbo-provider.xml: <?xml ve ...