时间限制: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的更多相关文章

  1. FatMouse's Speed——J

    J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  2. Hdu 1009 FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. hdu 1078 FatMouse and Cheese

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  4. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. FatMouse' Trade_贪心

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  6. [题解]hdu 1009 FatMouse' Trade(贪心基础题)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  7. 【HDU 1009】FatMouse' Trade

    题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...

  8. FatMouse的交易问题

    想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...

  9. hdu 1009:FatMouse' Trade(贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  10. HDU 1078 FatMouse and Cheese(记忆化搜索)

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. 用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败/OLE DB 错误: OLE DB 或 ODBC 错误 :

    用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败/OLE DB 错误: OLE DB 或 ODBC 错误 : 2012-2-23 上午 ,弄SAAS时,发现在生成多维数据集 ...

  2. CentOS(七)--Linux文件类型及目录配置

    这篇随笔将会对Linux系统的文件类型以及Linux的目录结构进行详细补充(linux中目录管理和权限非常重要,特别是在linux安装数据库类软件). 一.Linux更改文件权限的两种方式 在之前的一 ...

  3. CentOS(二)--初识linux的一些常用命令

    linux命令是对Linux系统进行管理的命令.对于Linux系统来说,无论是中央处理器.内存.磁盘驱动器.键盘.鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命 ...

  4. [改善Java代码]小心switch带来的空值异常

    使用枚举定义常量时,会伴有大量的switch语句判断,目的是伪类每个枚举项解释其行为,例如: public class Client { public static void main(String[ ...

  5. Linux 命令 - find: 搜索文件

    find 命令可以依据文件的各种属性在既定的目录(及其子目录)里搜索文件. 命令格式 find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [e ...

  6. Linux 命令 - killall: 通过进程名向进程发送信号

    命令格式 killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME... killall -l, --list killall -V, ...

  7. Oracle的GUID:Raw(16)

    最近用了Oracle作为开发的数据库.以前用Sqlserver的时候用GUID作为主键的(数据类型:uniqueidentifier),Oracle的GUID类型变成RAW(16)了.从数据库读出来R ...

  8. 在Tomcat中配置基于springside的项目

    注意点: Tomcat默认没有配置Transaction,需要在/Conf/Context.xml配置 1 <Transaction factory="org.objectweb.jo ...

  9. 第五十六篇、OC打开本地和网络上的word、ppt、excel、text等文件

    iOS打开本地和网络上的word.ppt.excel.text等文件 iOS开发过程中可能需要预览一些文件,这些文件的格式可能有word.ppt.excel等文件格式.那么系统提供两个类去预览这些文件 ...

  10. iOS app应用界面加载卡顿的问题

    刚发布版本,忽然发现加载界面需要3-5秒延迟,那么问题来了. 首先,发现问题: 1.看代码,基于之前版本更新都没出问题,还是比较确信不是代码中的bug,以防万一,还是仔细看了下关于界面跳转部分的代码, ...