HDU1009FatMouse' Trade(贪心)
Problem Description
The
warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and
requires F[i] pounds of cat food. FatMouse does not have to trade for all the
JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he
pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning
this homework to you: tell him the maximum amount of JavaBeans he can
obtain.
Input
begins with a line containing two non-negative integers M and N. Then N lines
follow, each contains two non-negative integers J[i] and F[i] respectively. The
last test case is followed by two -1's. All integers are not greater than
1000.
Output
accurate up to 3 decimal places, which is the maximum amount of JavaBeans that
FatMouse can obtain.
Sample Input
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
13.333
31.500
Author
Source
#include<stdio.h>
#include<algorithm>//sort的头文件
using namespace std;
const int maxn=+;
struct node{
double j,f;
double r;
}a[maxn];
bool cmp(node a,node b)//从大到小排序
{
return a.r>b.r;
}
int main()
{
int m,n,i;
double sum;
while(scanf("%d%d",&m,&n)==&&(m!=-&&n!=-))
{
for(i=;i<n;i++){
scanf("%lf%lf",&a[i].j,&a[i].f);
a[i].r=a[i].j/a[i].f;
}
sort(a,a+n,cmp);
sum=0.0;
for(i=;i<n;i++)
{
if(m>=a[i].f)
{
sum+=a[i].j;
m-=a[i].f;
}
else
{
sum+=(a[i].r)*m;
break;
}
}
printf("%.3lf\n",sum);
}
return ;
}
HDU1009FatMouse' Trade(贪心)的更多相关文章
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- HDOJ.1009 FatMouse' Trade (贪心)
FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...
- hdoj1009 FatMouse' Trade——贪心算法
贪心思路:按单位猫粮能兑换到的javaBean从大到小将组合进行排序,总是在当前兑换尽可能多的javabeans 问题描述:点击打开链接 hdoj1009 FatMouse's Trade 源代码: ...
- ZOJ FatMouse' Trade 贪心
得之我幸,不得,我命.仅此而已. 学姐说呀,希望下次看到你的时候依然潇洒如故.(笑~) 我就是这么潇洒~哈哈. 感觉大家比我还紧张~ 我很好的.真的 ------------------------- ...
- FatMouse' Trade (贪心)
#include <iostream> #include <stdio.h> #include <cstring> #include <cmath> # ...
- SGU 280.Trade centers(贪心)
SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solu ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- 20181009noip HZ EZ 两校联考trade(优先队列,贪心)
题面戳这里 思路: 裸的,贪心... 考场上写了一个数据分治(70ptsDP,30pts线段树优化贪心,GG了后30分) 这道题其实很简单的 我们看图: 我们在A时刻买一个东西,在B时刻卖出去,我们可 ...
随机推荐
- struts2框架学习(二)
---恢复内容开始--- 一.搭建步奏 1.新建web项目,进行必备Jar包的拷贝,放到lib目录以便项目的引用. 2.拷贝框架的核心配置文件Struts.xml,放到src目录下,保留一个基本配置即 ...
- JNDI中 java:comp/env 的理解
J2EE 上下文环境变量前缀,一般有如下几种:java:/comp/env/jdbcjava:/comp/env/urljava:/comp/env/mailjava:/comp/env/jms在部署 ...
- postgresql----serial类型和序列
postgresql序列号(SERIAL)类型包括smallserial(smallint,short),serial(int)和bigserial(bigint,long long int),不管是 ...
- .Net异步函数存在的限制
本文摘录自CLR Via C# 第四版. 异步函数存在以下限制: 1.不能讲应用程序的Main方法转变成异步函数.另外,构造器.属性访问器方法和时间访问器方法不能转变成异步函数. 2.异步函数不能使用 ...
- CentOS 6.5 安装MySQL5.7 RPM
一.新特性 MySQL 5.7可谓是一个令人激动的里程碑,在默认了InnoDB引擎的基础上,新增了ssl.json.虚拟列等新特性.相对于postgreSQL和MariaDB而言,MySQL5.7做了 ...
- [转]RadStudio DELPHI/C++ BUILDER Berlin 10.1 Update2安装破解教程
源链接:http://bbs.fishc.com/thread-76730-1-1.html 免责声明:本教程所有资源均为学习交流之用,软件和资料版权归原开发公司所有,请于下载后24小时内删除,禁止用 ...
- W: http://archive.ubuntukylin.com:10006/ubuntukylin/dists/xenial/InRelease: Signature by key 6CE35A4EBAB676094476BE7CD259B7555E1D3C58 uses weak digest algorithm (SHA1)
新装ubuntukylin 16.04,sudo apt-get update 时遇到如下问题: Hit:1 http://archive.ubuntukylin.com:10006/ubuntu ...
- homebrew for mac
注意 如果bash_profile 文件路径写错了,而导致很多命令不能使用 可以在终端 /usr/bin/vim ~/.bash_profile 打开编辑 esc退出 按冒号(:)再按wq ...
- 面向对象UML中类关系
如果你确定两件对象之间是is-a的关系,那么此时你应该使用继承:比如菱形.圆形和方形都是形状的一种,那么他们都应该从形状类继承而不是聚合.如果你确定两件对象之间是has-a的关系,那么此时你应该使用聚 ...
- Linux Curl常用命令使用【转】
Curl是Linux下一个很强大的http命令行工具,其功能十分强大. 1)读取网页 $ curl linuxidc.com">http://www.linuxidc.com 2)保存 ...