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

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

 #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. [翻译] BBCyclingLabel

    BBCyclingLabel BBCyclingLabel is just like a UILabel but allows you to perform custom animations whe ...

  2. [Swift] 创建一个对象

    创建一个对象 先写一个People类 // // People.swift // Class // // Created by YouXianMing on 15/3/18. // Copyright ...

  3. Linux入门-7 Linux管道、重定向以及文本处理

    Linux管道.重定向以及文本处理 1 Linux多命令协作:管道及重定向 管道和重定向 2 Linux命令行文本处理工具 文件浏览 基于关键字搜索-grep 基于列处理文本-cut 文本统计-wc ...

  4. c++的路上,我坚信,我可以 -----第四次作业体会

    第四次作业 传送门 1.浅谈"新对象"sstream和stack 第四次作业,就是在第三次作业上作修改,上周周末,我刚刚才完成了第三次作业,但是知道了队列如何应用,面对这次的sta ...

  5. Running Protractor Tests on Docker

    配置这个Protractor环境真是折磨死人了,webdriver-manage update怎么都不成功,即使自己下载好chromederiver放到相应文件夹下,也不能使用.费时三四天终于按照ht ...

  6. gluoncv 导入方式

    了解了sys.path和python 的import 的话,之前修改gluoncv 的方式就可以有了新的简单的方法: 如果你pip install gluoncv的,然后脚本又git clone了,发 ...

  7. 绕过disable_functions执行命令实验

    绕过disable_functions执行命令实验 看下disable函数,所有命令函数都被禁用: 编译64位共享库: 命令成功执行: 参考链接: https://www.freebuf.com/ar ...

  8. python反序列化

    import pickle import os class A(object): def __reduce__(self): a = """python -c 'impo ...

  9. 【Vue】vue.js常用指令

    http://www.cnblogs.com/rik28/p/6024425.html Vue.js的指令是以v-开头的,它们作用于HTML元素,指令提供了一些特殊的特性,将指令绑定在元素上时,指令会 ...

  10. 23、springboot与缓存(1)

    一.JSR107 Java Caching定义了5个核心接口,分别是CachingProvider, CacheManager, Cache, Entry 和 Expiry. 1.CachingPro ...