【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 ...
随机推荐
- C# ODP.Net oracle数据库操作 支持不安装客户端
下载: http://download.oracle.com/otn/other/ole-oo4o/ODTwithODAC1110720.zip?AuthParam=1414811820_e61f2f ...
- cadence动态铜皮的参数设置
注意这幅图和上一幅图那个焊盘距离shape的间距,变大了,这个设置很用的.
- CAN总线电平(隐性与显性)
CAN2.0B规范定义了两种互补的逻辑数值:显性和隐性.同时传送显性和隐性位时,总线呈现显性状态:同时传送显性状态位时,总线呈现显性状态:同时传送隐性状态位时,总线呈现隐性状态.显性数 ...
- 后端工具——Maven——初篇——目录
目录 Maven的知识体系包括四个部分.Maven的配置文件,Maven命令,Maven生命周期,Maven插件.在介绍Maven之前,首先需要介绍如何安装Maven. 安装:介绍Maven在Linu ...
- td标签内容:换行和不换行设置
td标签内容:换行和不换行设置 固定td内容不换行:<td style="white-space:nowrap">内容</td>或<td nowrap ...
- 一些常用的css
不换行 white-space:nowrap table纵向合并的单元格垂直居中 display:table-cell; vertical-align:middle; table合并横向单元格 c ...
- 简单实现一个button控制两种状态
<button class="btn a-bgcolor" data-toggle="tooltip" data-placement="left ...
- js实现Set
class MySet { constructor(params) { if (typeof params[Symbol.iterator] !== 'function') { throw new T ...
- 使用pyaudio播放无损音乐(wav)
安装pyaudio sudo apt-get install python-pyaudio python3-pyaudio pip3 install pyaudio 执行第二步可能会遇到如下错误: 根 ...
- springboot无法查询到后台的数据
问题:springbooot中,整合mybatis时,在IUserMapper接口中, @Select("select * from user where name like '%李%'&q ...