FatMouse
时间限制:1 秒
内存限制:128 兆
特殊判题:否
提交:1431
解决:641
- 题目描述:
-
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
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.
- 输入:
-
The input consists of multiple test cases. Each test case 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.
- 输出:
-
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
- 样例输入:
- 5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
- 样例输出:
- 13.333
31.500#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std; struct goods
{
int J,F;
double xinjia;
}buf[]; bool cmp(goods a,goods b)
{ return a.xinjia<b.xinjia;
} int main()
{
int m,n,j,f;
while(cin>>m)
{
cin>>n;
if(m==-&&n==-) break;
int i;
for(i=;i<n;i++)
{
cin>>j>>f;
buf[i].J=j;
buf[i].F=f;
buf[i].xinjia=(double)f/j;
}
sort(buf,buf+n,cmp); double sum=0.0;
for(i=;i<n;i++)
{
if(buf[i].F<m)
{
sum=sum+buf[i].J;
m=m-buf[i].F;
}
else
{
sum=sum+buf[i].J*(double)m/buf[i].F;
break;
}
} cout<<fixed<<setprecision()<<sum<<endl; }
return ;
} /**************************************************************
Problem: 1433
User: 2009declan
Language: C++
Result: Accepted
Time:10 ms
Memory:1536 kb
****************************************************************/
FatMouse的更多相关文章
- FatMouse's Speed——J
J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1078 FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- FatMouse' Trade_贪心
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- 【HDU 1009】FatMouse' Trade
题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...
- FatMouse的交易问题
想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1078 FatMouse and Cheese(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- python(3)-队列
队列分为双向队列和单向队列: 对于双向队列,同样需要先import collections 创建队列 >>> import collections >>> d = ...
- Ionic中弹窗
Ionic中弹窗有两种ionicModal和ionicPopup; $ionicModal是完整的页面: $ionicPopup是(Dialog)对话框样式的,直接用JavaScript设定对话框的一 ...
- CF Covered Path (贪心)
Covered Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- poj 2724 二分图最大匹配
题意: 会给出M个串,我们要做的就是将这M个串给清除了.对于任意两个串,若二进制形式只有一位不一样,那么这两个串可以在一次操作消除,否则每个操作只能消除一个串. 3 3 *01 100 011 可以代 ...
- listagg( ) within group ( order by ) 与 wm_concat
listagg( ) within group ( order by ) 与 wm_concat --oracle 11g 及以后适合 最好 select spbywslid,listagg(xm,' ...
- 关于java.lang.NullPointerException: Module 'null' not found.的问题
在用eclipse做struts1项目时,配置都ok了.可是一运行就报java.lang.NullPointerException: Module 'null' not found.错. 代码如下: ...
- Ehcache(2.9.x) - API Developer Guide, Cache Exception Handlers
About Exception Handlers By default, most cache operations will propagate a runtime CacheException o ...
- ZooKeeper(3.4.5) - 配置伪集群模式
1. 准备 Java 运行环境,需要安装 Java1.6 或更高版本的 JDK. 2. 下载 ZooKeeper 的稳定版本 zookeeper-x.x.x.tar.gz,将其解压,约定目录名称为 % ...
- iPad accessory communication through UART
We manufacture a new accessory for iPad/iPhone which should transfer commands to the iPad. We like t ...
- HTML+CSS学习笔记 (7) - CSS样式基本知识
HTML+CSS学习笔记 (7) - CSS样式基本知识 内联式css样式,直接写在现有的HTML标签中 CSS样式可以写在哪些地方呢?从CSS 样式代码插入的形式来看基本可以分为以下3种:内联式.嵌 ...