【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 ...
随机推荐
- [CF467C] George and Job - DP,前缀和
简单dp + 前缀和 你谷这乱标难度的风气真是-- #include <bits/stdc++.h> using namespace std; #define int long long ...
- HTML列表,表格与媒体元素
一.无序列表 <ul> <li>无序列表</li> <li>有序列表</li> <li>自定义列表</li> < ...
- too old
The working copy at “” is too old (format 10) to work with client version ‘1.9.7(r18000392)’ 原因:svn版 ...
- laravel框架实现发送邮件的功能
1.在config 下的mail.php中配置(配置后面的两个就行了) 'from' => [ 'address' => env('MAIL_FROM_ADDRESS', '7623018 ...
- java中成员变量,局部变量,静态变量的辨析
转自百度:https://baijiahao.baidu.com/s?id=1625360816541592483&wfr=spider&for=pc 1.java中成员变量,局部变量 ...
- 2.sleep和wait的区别:
sleep是Thread类的方法,wait是object(Java类库的老祖宗)的方法 sleep阻塞的线程在指定时间后,会转变为可执行状态:wait它要等待notify的唤醒 执行了sleep的线程 ...
- Microsoft 常用下载链接
申明:本文所有下载链接皆来自微软官网,推荐使用迅雷下载 推荐:Windows10安装时选择专业版,Office用2016版,其他随意,具体用哪个版本根据配置和需求 Windows系统下载 Window ...
- Virtual Judge POJ 1328 Radar Installation
贪心 #include<algorithm> #include<iostream> #include<cstdio> #include<cmath> u ...
- Linux - Shell - find - 进阶: 范围
概述 继续昨天的 find 背景 还有一些 过滤条件 1. 约束: 目录层数 概述 约束目录的层级 选项 -maxdepth 作用 约束最大目录层级 相对路径 -mindepth 作用 约束最小目录层 ...
- artTemplate使用说明
普通使用 <script id="test" type="text/html"> {{if isAdmin}} <h1>{{title} ...