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 ...
随机推荐
- MYSQL导入csv类型的数据出现The MySQL server is running with the --secure-file-priv option
今天尝试使用 into outfile导出数据的时候出现错误: The MySQL server is running with the --secure-file-priv option so it ...
- October 19th 2017 Week 42nd Thursday
If you remember me, then I don't care if everyone else forgets. 只要你记得我,我不介意整个世界都把我遗忘了. I can't follo ...
- Ecstore 默认图片压缩质量差的问题解决方法
修改app/image/lib/clip.php文件 }elseif( function_exists('imagecopyresampled')){ $quality = 80; $image_p ...
- sublime设置node.js编译
1. 首先需安装node环境并配置好环境变量,安装教程. 2. 然后在sublime中打开工具(Tools)→编译系统(Build System)→新编译系统(New Build System) 3. ...
- oracle 批量更新merge语句
merge into (SELECT * FROM QUERY_DB1.test_MPOS ) T1 using (SELECT FLAG FLAG1,IN_MNO FROM QUERY_DB1.t ...
- JavaScript 删除数组中的对象
1.获得对象在数组中的下标 function (_arr,_obj) { var len = _arr.length; for(var i = 0; i < len; i++){ if(_arr ...
- Advanced Javascript outlining插件说明
Advanced Javascript outlining插件 用途:在js文件中写入#region/#endregion代码组合段,可收缩和展开.类似于后台页面的region用法. 效果截图如下(前 ...
- vue中的img src 动态加载本地json的图片路径写法。
目录: 注意:本地json文件和json文件里的图片地址都必须写在static 静态文件夹里:否则json文件里的url地址找不到. major_info.json文件里的图片路径写法 页面通过v-b ...
- # 20155319 Exp3 免杀原理与实践
20155319 Exp3 免杀原理与实践 基础问题 (1)杀软是如何检测出恶意代码的? 基于特征码的检测 启发式的恶意软件检测 基于行为的恶意软件检测 (2)免杀是做什么? 免杀,从字面进行理解,避 ...
- MAC下配置ssh让SourceTree通过秘钥访问远程仓库
问题描述 由于TortoiseGit没有MAC版本,我们使用了SourceTree来替代. 在帮同事解决Mac下的Git的时候,碰到一个问题:SourceTree无法使用ssh方式提交代码,这是由于没 ...