PAT甲题题解-1070. Mooncake (25)-排序,大水题
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h> using namespace std;
/*
3 0
180 150 100
7.5 7.2 4.5
*/
const int maxn=+;
int amounts[maxn];
float price[maxn]; struct Cake{
float amounts; //注意,这里得设置成浮点型,若是int一个样例会过不了
float price;
float unitprice=;
bool operator<(const Cake tmp)const{
return unitprice>tmp.unitprice;
}
}cake[maxn];
int main()
{
int n,d;
scanf("%d %d",&n,&d);
for(int i=;i<n;i++){
scanf("%f",&cake[i].amounts);
}
for(int i=;i<n;i++){
scanf("%f",&cake[i].price);
cake[i].unitprice=cake[i].price/cake[i].amounts;
}
sort(cake,cake+n);
float ans=;
for(int i=;i<n;i++){
if(d>=cake[i].amounts){
ans+=cake[i].price;
d-=cake[i].amounts;
}
else{
ans+=(d/cake[i].amounts)*cake[i].price;
break;
}
}
printf("%.2f",ans);
return ;
}
PAT甲题题解-1070. Mooncake (25)-排序,大水题的更多相关文章
- PAT甲题题解-1032. Sharing (25)-链表水题
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT甲题题解-1012. The Best Rank (25)-排序水题
排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- PAT甲题题解-1010. Radix (25)-二分搜索
题意:给出n1和n2,以及其中一个数的进制,问另一个数是多少进制的情况下,才会是两个数相等.不存在的话,则输出Impossible 这题思路很简单,但是要考虑的比较多,在简单题里面算是比较好的. 有两 ...
- PAT甲题题解-1003. Emergency (25)-最短路径+路径数目
给出n个城市,m条边,起始点c1和目的点c2接下来给出n个城市的队伍数以及m条双向边问你求c1到c2的所有最短路径数目,以及其中经过的最多队伍数 先最短路dijkstra,同时建立vector数组pr ...
- PAT甲题题解-1029. Median (25)-求两序列的中位数,题目更新了之后不水了
这个是原先AC的代码,但是目前最后一个样例会超内存,也就是开不了两个数组来保存两个序列了,意味着我们只能开一个数组来存,这就需要利用到两个数组都有序的性质了. #include <iostrea ...
- PAT甲题题解-1078. Hashing (25)-hash散列
二次方探测解决冲突一开始理解错了,难怪一直WA.先寻找key%TSize的index处,如果冲突,那么依此寻找(key+j*j)%TSize的位置,j=1~TSize-1如果都没有空位,则输出'-' ...
- PAT 1070. Mooncake (25)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
随机推荐
- SVN 远程访问
第一种方法 https://www.cnblogs.com/Leo_wl/p/3475167.html#_label0 默认协议为:https 端口号:443 服务器地址:https://主机名/sv ...
- Mojave使用pyenv安装python-zlib错误
mojave使用pyenv编译python出现 zipimport.ZipImportError: can't decompress data; zlib not available错误 解决方案: ...
- wx.aui.AuiManager部分/布局翻译
wx.aui.AuiManager wx.aui.AuiManager 是AUI框架类中的主要类 wx.aui.AuiManager管理于指定的wx.Frame相关联的窗口,通过使用窗口的wx.aui ...
- 8.2Solr API使用(Facet查询)
转载请出自出处:http://eksliang.iteye.com/blog/2165882 一)概述 Facet是solr的高级搜索功能之一,可以给用户提供更友好的搜索体验.在搜索关键字的同时,能够 ...
- Swift 并行编程现状和展望 - async/await 和参与者模式
这篇文章不是针对当前版本 Swift 3 的,而是对预计于 2018 年发布的 Swift 5 的一些特性的猜想.如果两年后我还记得这篇文章,可能会回来更新一波.在此之前,请当作一篇对现代语言并行编程 ...
- 死磕nginx系列--nginx入门
nginx 功能介绍 Nginx因为它的稳定性.丰富的模块库.灵活的配置和低系统资源的消耗而闻名.业界一致认为它是Apache2.2+mod_proxy_balancer的轻量级代替者,不仅是因为响应 ...
- Dig命令解析结果
dig -t RT NAME @NS -t RT 指定要查询的资源记录类型 NAME 需要解析的域(域名) @NS 指定那个域名服务器负责解析 [root@xss ~]# dig www.ihoney ...
- Jenkins忘记密码解决办法
1.进入 如果安装的war包,路劲如下: C:\Users\LENOVO\.jenkins\ 2.打开config.xml ->将useSecurity设置为false 3.进入系统管理的管理 ...
- Python2.7-struct模块
struct模块 处理二进制数据,与C语言交互,可以较为方便的对C语言的struct类型和python中的数据进行转换 主要是用于将int,char之类的C语言中基础数据pack至一个二进制流的字符串 ...
- HDU3853:LOOPS
题意:迷宫是一个R*C的布局,每个格子中给出停留在原地,往右走一个,往下走一格的概率,起点在(1,1),终点在(R,C),每走一格消耗两点能量,求出最后所需要的能量期望 #include<i ...