FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 45970    Accepted Submission(s): 15397

Problem Description
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.
Input
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.
 
Output
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.
Sample Input
5 3
7 2
4 3
5 2
20 3
25 18
24 15  
15 10
-1 -1
Sample Output
 #include<stdio.h>
void bubblesort(double v[],int w[],int f[],int n)
{
int i,j;
double t;
for(i=;i<=n;i++)
{
for(j=i+;j<=n;j++)
{
if(v[i]>v[j])
{
t=v[i];
v[i]=v[j];
v[j]=t; t=f[i];
f[i]=f[j];
f[j]=t; t=w[i];
w[i]=w[j];
w[j]=t;
}
}
}
}
int main()
{
int n,m,i,w[],f[];
double v[],sum;
while(scanf("%d %d",&m,&n)!=EOF&&(n!=-)&&(m!=-))
{
for(i=;i<=n;i++)
{
scanf("%d %d",&w[i],&f[i]);
v[i]=f[i]*1.0/w[i];
}
bubblesort(v,w,f,n); sum=;
for(i=;i<=n&&v[i]<=m&&m>;i++)
{ if(m>=f[i])
{
sum+=w[i];
m=m-f[i];
}
else
{
sum+=m*1.0/v[i];
m=;
}
}
printf("%.3lf\n",sum);
}
}

HDU_1009_FatMouse' Trade的更多相关文章

  1. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

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

  2. Hdu 1009 FatMouse' Trade

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

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

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

  4. ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)

    题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...

  5. HDU 3401 Trade dp+单调队列优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...

  6. 【HDU 1009】FatMouse' Trade

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

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

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

  8. 杭电1009-FatMouse' Trade

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

  9. Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏

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

随机推荐

  1. moment倒计时插件

    https://github.com/icambron/moment-countdown

  2. [C++]STL容器Vector的内存释放

    直接抛出两句话,说明到底应该如何释放Vector占用的内存. “vector的clear不影响capacity,你应该swap一个空的vector.” <Effective STL>中的“ ...

  3. 取消a标签的页面跳转

    如果代码是:<a href="#" class="juan-btn" onclick="showResult()">提交< ...

  4. 持续集成:TestNG组织如何测试用例

    持续集成:TestNG组织如何测试用例   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:90 ...

  5. Java类修饰符

  6. 原生tab切换

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  7. 常用linux命令及其设置

    完成一个运维的工作,以下的命令和配置是经常会用到的,总结一下工作以来的命令和配置 linux常用命令 linux客户端挂接(mount)其他linux系统或UNIX系统的NFS共享 $ mkdir – ...

  8. MySQL学习笔记(三)—索引

    一.概述 1.基本概念       在大型数据库中,一张表中要容纳几万.几十万,甚至几百万的的数据,而当这些表与其他表连接后,所得到的新的数据数目更是要大大超出原来的表.当用户检索这么大量的数据时,经 ...

  9. JQgrid表格的使用

    html部分: <div class="tab"> <table id="datatable"></table>      ...

  10. 一个只有99行代码的JS流程框架

    张镇圳,腾讯Web前端高级工程师,对内部系统前端建设有多年经验,喜欢钻研捣鼓各种前端组件和框架. 最近一直在想一个问题,如何能让js代码写起来更语义化和更具有可读性. 上周末的时候突发奇想,当代码在运 ...