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

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

 #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. CSV输入输出

    读取csv文件: import csv cf = open('D:\pywe.csv','rb') cf.readline() #读取标题行,光标移动到下一行(相当于调过标题行) for l in c ...

  2. Python学习---线程/协程/进程学习 1220【all】

    Python学习---线程基础学习 Python学习---线程锁/信号量/条件变量同步1221 Python学习---同步条件event/队列queue1223 Python学习---进程 1225 ...

  3. Linxu下 expect的安装与使用

    expect学习 1.什么是except        Expect是基于Tcl的一个相对简单的免费脚本文件语言工具,用于实现自动和交互式程序进行通信            is a software ...

  4. sql根据子查询更新语句

    update … from语句 测试环境准备 create table #table1 ( id ) ); go create table #table2 ( id ) ); go , , , , , ...

  5. scala当中的特质trait

    1.将trait作为接口使用 Scala中的trait是一种特殊的概念: 首先先将trait作为接口使用,此时的trait就与Java中的接口 (interface)非常类似: 在trait中可以定义 ...

  6. U-Mail:邮件营销如何大量获取并筛选有效地址

    工欲善其事必先利其器,在所有的邮件推广中,最基础的工作就是收集到足够多的有效邮箱地址,俗话说韩信将兵多多益善,邮箱地址越多,也就意味着潜在的转化为消费者的数量众多,但是如果大量滥竽充数的地址被搜罗进来 ...

  7. 中间人攻击利用框架bettercap测试

    0x00前言 上篇提到内网渗透很有趣,这次就从一款新工具说起: bettercap 0x01简介 bettercap可用来实现各种中间人攻击,模块化,便携.易扩展 0x02特点 提到中间人攻击,最知名 ...

  8. Python的优雅写法

    枚举 之前我们这样操作:           Python   1 2 3 4 i = 0 for item in iterable:     print i, item     i += 1 现在我 ...

  9. CF712D Memory and Scores

    题目分析 实际上两个人轮流取十分鸡肋,可以看作一个人取2t次. 考虑生成函数. 为了方便,我们对取的数向右偏移k位. 取2t次的生成函数为: \[ F(x)=(\sum_{i=0}^{2k}x_i)^ ...

  10. 使用loader打包静态文件-样式2

    这篇我们了解下css-loader常用的配置项,要配置的话,use里面就不再是一个字符串了 // 打包模块不知道该怎么办,就去模块配置里面该怎么办 module: { // 规则 rules: [{ ...