hdu1009 - 贪心
2017-07-14 18:18:31
- writer:pprp
- 介绍:hdu1009
- 题目介绍,详见hdu1009
- 代码如下
#include <iostream>
#include <algorithm>
#include <cstdio>
#include<iomanip> using namespace std; const int maxn = ; class mouse
{
public:
int j;
int f;
int divide;
}; bool cmp(mouse m1,mouse m2)
{
if(m1.divide > m2.divide)
return true;
else
return false;
} int main()
{
int m,n; mouse mou[maxn];
while(cin >> m >> n && m != - && n != -)
{
double lp = ;
for(int i = ; i < n ; i++)
{
mou[i].f = ;
mou[i].j = ;
mou[i].divide = ;
} for(int i = ; i < n ; i++)
{
cin >> mou[i].j>>mou[i].f;
mou[i].divide = mou[i].j/mou[i].f;
} sort(mou,mou+n,cmp); for(int i = ; i <n ; i++)
{
if(m >= mou[i].f)
{
m -= mou[i].f;
lp += mou[i].j; }
else
{
lp += mou[i].j*(m/(double)mou[i].f);
}
}
printf("%.3f\n",lp);
} return ;
}
hdu1009 - 贪心的更多相关文章
- HDU1009老鼠的旅行 (贪心算法)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU-1009(简单贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- HDU1009:FatMouse' Trade(初探贪心,wait)
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containi ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【BZOJ-4245】OR-XOR 按位贪心
4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 486 Solved: 266[Submit][Sta ...
随机推荐
- 安装canal
一.安装前准备 配置Mysql: [mysqld] log-bin=mysql-bin #添加这一行就ok binlog-format=ROW #选择row模式 server_id=1 #配置mysq ...
- Qt JSON解析生成笔记(把JSON转成一个类对象)
对于这样一段json { "name": "布衣食", "gender": "Male", "age" ...
- python插入记录后获取最后一条数据的id
python插入记录后取得主键id的方法(cursor.lastrowid和conn.insert_id()) 参考:https://blog.csdn.net/qq_37788558/article ...
- 001-ant design pro 页面加载原理及过程,@connect 装饰器
一.概述 以列表页中的标准列表为主 Ant Design Pro 默认通过只需浏览器单方面就可处理的 HashHistory 来完成路由.如果要切换为 BrowserHistory,那在 src/in ...
- 21.如何将java类对象转化为json字符串
使用阿里巴巴的fastJson 下载链接: 链接: https://pan.baidu.com/s/1dHjLOm1 密码: rr3w 用法如下: User user = new User(); us ...
- 简明python教程十一----更多Python的内容
特殊的方法 __init__(self,...):这个方法在新建对象恰好要被返回使用之前被调用 __del__(self):恰好在对象要被删除之前调用 __str__(self):我们对对象使用pri ...
- PAT 1148 Werewolf - Simple Version [难理解]
1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned i ...
- win10怎样取消电脑自动锁屏
笔记本经常用着用着就锁屏了 解决方法: 打开控制面板的电源选项,更改“使计算机进入睡眠状态”时间为“从不”.
- Linux系统——inode和block
Linux文件属性 磁盘被分区并格式化为ext4文件系统后,会生成一定数量的inode和block Inode 索引节点 作用:存放文件的属性信息以及作为文件的索引(指向文件的实体block) Blo ...
- Thread was being aborted.
异常:Thread was being aborted.(正在终止线程) 网上很多人说Response.redirect或Response.write()放在了try catch块中引起 百度一下就可 ...