【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意:
输入两个正整数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 分)(贪心水中水)的更多相关文章
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- PAT Advanced 1070 Mooncake (25) [贪⼼算法]
题目 Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many typ ...
- PTA PAT排名汇总(25 分)
PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- wcf接口输出为json格式
接口定义: [OperationContract] [WebInvoke(UriTemplate = "AddTask?taskId={taskId}&processGuid={pr ...
- python 数组array的一些操作
对一些特定大小的元素进行操作 1.将数组Arr中大于100的值都设定为100 Arr[Arr >100] = 100 利用array索引的内置 numpy.minimum(Arr, 100 ...
- 零Web知识个性化Blog
需要使用到的工具 Chrome Pycharm 自定主题的CSS 申请博客的Js权限 设置博客选项 打开Chrome修改查看CSS样式,Windows(F12),MacOS(Command+Optio ...
- laravel-middleware中间件常用使用方法
介绍 中间件提供了一种方便的机制过滤进入应用程序的 HTTP 请求.例如,Laravel 包含一个中间件,验证您的应用程序的用户身份验证.如果用户未被认证,中间件会将用户重定向到登录界面.然而,如果用 ...
- hadoop cdh 的那些坑 第二弹
卧槽 ....一直连不上datanode 不知道为什么数据节点一直连接不上.. 2019-07-19 16:10:00,156 INFO org.apache.hadoop.ipc.Client: R ...
- Thymeleaf th:include,th:replace使用
来自:https://blog.csdn.net/believe__sss/article/details/79992408
- Redis Distributed lock
using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using ...
- 题解【洛谷P2668】[NOIP2015]斗地主
题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的 $ A $ 到 $ K $ 加上大小王的共 $ 54 $ 张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据 ...
- 初识Docker:BusyBox容器后台运行失败
1.问题描述:我在进行Docker网络实验时,使用docker run -d busybox命令时,busybox无法保持后台长期运行. ============================ ...
- B/S架构和C/S的区别
经常在招聘网站上看到要求熟悉B/S C/S架构,具体含义是: B/S---Browser/Server 浏览器/服务器模式 C/S---Client/Server 客户端/服务器模式 通俗点讲: ...