题意:

输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全部出手的利润。输出最大利润。

trick:

测试点2可能包含M不为整数的数据。(尽管题面说明M是正整数,可是根据从前PAT甲级题目的经验,有可能不是整数。。。。。)

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
double a[];
double b[];
pair<double,int>p[];
int main(){
int n;
double m;
scanf("%d%lf",&n,&m);
for(int i=;i<=n;++i)
scanf("%lf",&a[i]);
for(int i=;i<=n;++i)
scanf("%lf",&b[i]);
for(int i=;i<=n;++i)
p[i].first=b[i]/a[i],p[i].second=i;
sort(p+,p++n);
double sum=;
double ans=;
for(int i=n;i;--i)
if(sum+a[p[i].second]<=m){
sum+=a[p[i].second];
ans+=b[p[i].second];
}
else{
ans+=(m-sum)*p[i].first;
break;
}
printf("%.2f",ans);
return ;
}

【PAT甲级】1070 Mooncake (25 分)(贪心水中水)的更多相关文章

  1. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

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

  2. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  3. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  4. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  5. PAT Advanced 1070 Mooncake (25) [贪⼼算法]

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

  6. PTA PAT排名汇总(25 分)

    PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...

  7. PAT 甲级 1067 Sort with Swap(0, i) (25 分)(贪心,思维题)*

    1067 Sort with Swap(0, i) (25 分)   Given any permutation of the numbers {0, 1, 2,..., N−1}, it is ea ...

  8. PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)

    1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...

  9. PAT-2019年冬季考试-甲级 7-3 Summit (25分) (邻接矩阵存储,直接暴力)

    7-3 Summit (25分)   A summit (峰会) is a meeting of heads of state or government. Arranging the rest ar ...

随机推荐

  1. Django教程(2)

    from Django official document; Django 最初被设计用于具有快速开发需求的新闻类站点,目的是要实现简单快捷的网站开发. from 编写你的第一个 Django 应用, ...

  2. Window逆向基础之逆向工程介绍

    逆向工程 以设计方法学为指导,以现代设计理论.方法.技术为基础,运用各种专业人员的工程设计经验.知识和创新思维,对已有产品进行解剖.深化和再创造. 逆向工程不仅仅在计算机行业.各行各业都存在逆向工程. ...

  3. spring boot 运行错误: 找不到或无法加载主类

    在项目根目录运行 mvn clean install 进行重新编译 不行的话就删了原有的启动配置,重新配置启动.

  4. Having用法以及其和Where区别

    例如,进行分组语句: select year,count(id) num from tblPlantProduce group by year 在这条语句中若要筛选出年份>2005年的有两种方式 ...

  5. spring(四):DI流程

    在IoC容器初始化过程中,一般不包含Bean依赖注入的实现. 依赖注入一般发生在应用第一次向容器获取Bean时(getBean),但是有一个例外. 在使用IoC容器时有一个预实例化的配置,即通过laz ...

  6. 根据wsdl生成soap请求格式

    本文链接:https://blog.csdn.net/a_Little_pumpkin/article/details/84725118根据wsdl文件如何生成soap请求的格式呢?使用最方便的工具S ...

  7. Windows10安装node.js

    1.下去官网下载node.js https://nodejs.org/zh-cn/download/ 2.安装,直接默认即可,安装路径也可以自己选择 3.设置环境变量 1.安装软件,若是-g,则是全局 ...

  8. 【音乐欣赏】《Abnormalize》 - 凛として時雨

    曲名:Abnormalize 作者:凛として時雨 [00:00.96]誰にも見せられないもの [00:06.44]頭の中溢れて [00:11.96]間違いさえも無い世界へ [00:17.16]迷い込ん ...

  9. Iris项目结构

  10. Docker 基本命令和使用

    Docker 基本命令 systemctl start docker : 启动 Docker systemctl stop docker : 停止 Docker systemctl restart d ...