时间限制: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. Visual studio 2013 添加 GitHub

  2. oracle数据库 PSU,SPU(CPU),Bundle Patches 和 Patchsets 补丁号码快速参考 (文档 ID 1922396.1)

    数据库 PSU,SPU(CPU),Bundle Patches 和 Patchsets 补丁号码快速参考 (文档 ID 1922396.1) 文档内容   用途   详细信息   Patchsets ...

  3. Oracle 版本查看及版本号说明

    http://blog.163.com/magicc_love/blog/static/185853662201210194592757/ select * from v$version; 或sele ...

  4. Web系统大规模并发----电商秒杀与抢购

    原文链接请参见:http://uule.iteye.com/blog/2186786

  5. Microsoft.SharePoint.Security的问题

    请求“Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0 ...

  6. Jersey(1.19.1) - Root Resource Classes

    Root resource classes are POJOs (Plain Old Java Objects) that are annotated with @Path have at least ...

  7. MongoDB - Introduction to MongoDB, BSON Types

    BSON is a binary serialization format used to store documents and make remote procedure calls in Mon ...

  8. sql常识-FULL JOIN

    SQL FULL JOIN 关键字 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行. FULL JOIN 关键字语法 SELECT column_name(s) FROM table_n ...

  9. MSSQL Server 导入/导出到远程服务器

    1.打开本地企业管理器,先创建一个SQL Server注册来远程连接服务器端口SQL Server. 步骤如下图: 图1: 2.弹出窗口后输入内容."总是提示输入登陆名和密码"可选 ...

  10. jquery 解析xml字符串

    // 函数功能:把xml字符串转换成对象 function convertXmlStringToObj(xmlString) { var xmlObj = new Object; var xmlDoc ...