FatMouse' Trade

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

13.333
31.500
//本题是简单贪心问题。意思是老鼠有m榜猫粮,通过给猫粮东西data[i].b能够兑换data[i].a,求最多能够兑换多少食物。

//仅仅需将data[i].a/data[i].b的值从大到小排序就可以求解。

#include<stdio.h>
struct st
{
double a;
double b;
double c;
}data[1000];
int main()
{
int i,j,m,n;
struct st data[1000],t;
while(scanf("%d %d",&m,&n)&&(m!=-1||n!=-1))
{
double sum=0.000;
for(i=0;i<n;i++)
{
scanf("%lf %lf",&data[i].a,&data[i].b);
}
for(i=0;i<n;i++)
{
for( j=i+1;j<n;j++)
{
if((data[i].a/data[i].b)<data[j].a/data[j].b)
{
t=data[i];
data[i]=data[j];
data[j]=t;}
}
}
for(i=0;i<n;i++)
{
if(m-data[i].b>=0.001)
{
sum+=data[i].a;
m-=data[i].b;
}
else
{
sum=sum+m*data[i].a/data[i].b;
break;
}
}
printf("%.3lf\n",sum);
}
return 0;
}

FatMouse&#39; Trade(杭电1009)的更多相关文章

  1. 杭电 1009 FatMouse' Trade (贪心)

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

  2. HDU 1009:FatMouse&#39; Trade(简单贪心)

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

  3. hdu 1009 FatMouse&#39; Trade

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

  4. ZOJ 2109 FatMouse&#39; Trade (背包 dp + 贪婪)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat ...

  5. 杭电--1009 C语言实现

    思路:要用有限的猫粮得到最多的javabean,则在房间中得到的javabean比例应尽可能的大. 用一个结构体,保存每个房间中的javabean和猫粮比例和房间号,然后将结构体按比例排序,则从比例最 ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 杭电dp题集,附链接还有解题报告!!!!!

    Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...

  8. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  9. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

随机推荐

  1. python2.7 串口操作方式 编译 .py为windows可运行exe文件

    一 python操作串口 首先下载安装串口模块pyserial . 代码实现: import serial ser = serial.Serial('/dev/ttyUSB2', 115200) pr ...

  2. ASP.NET页面之间传值

    介绍: 在网页应用程序的开发中,页面之间的传值应该是最常见的问题了. 在这篇文章里,azamsharp 将为我们介绍一些ASP.NET页面传值的方式.本文所举的例子非常简单,仅仅包含了一个文本框和几个 ...

  3. html submit 登录

    <!doctype html> <html lang="en"> <head> <meta name="Generator&qu ...

  4. Swift学习之UI开发初探

    Swift是供iOS和OS X应用编程的新编程语言.相信很多开发者都在学习这门新语言.废话不多说,下面我就来学习使用Swift创建一个简单的UI应用程序. AD: 概述 Apple近日发布了Swift ...

  5. android开发隐藏了actionbar仍然短暂闪现的解决方法

    有时候我们在代码里隐藏了actionbar,在打开应用时,仍然短暂闪现下actionbar,用户体验很不好.   最简单的方法是 在AndroidManifest.xml中设置主题中配置不显示titl ...

  6. webview 加载某些网页失败的处理办法(第七条)

    1.添加权限:AndroidManifest.xml中必须使用许可"android.permission.INTERNET",否则会出Web page not available错 ...

  7. vbox要手动mount才能挂载windows的共享文件夹(好用,不用安装samba了)

    mount -t vboxsf BaiduShare /mnt/bdshare/ 我按照这篇文章成功: http://www.wuji8.com/meta/448016166.html 其它参考: h ...

  8. 使用boost中的property_tree实现配置文件

    property_tree是专为配置文件而写,支持xml,ini和json格式文件   ini比较简单,适合简单的配置,通常可能需要保存数组,这时xml是个不错的选择.   使用property_tr ...

  9. 京JS 2013 - A two-day conference in Beijing for the JavaScript and Node.js community

    京JS 2013 - A two-day conference in Beijing for the JavaScript and Node.js community 关于技术大会 京JS 2013 ...

  10. Java面试题精选(三) JSP/Servlet Java面试逻辑题

    --   JSP/Servlet  Java面试逻辑题   --     很显然,Servlet/JSP的WEB前端动态制作的重要性比HTML/CSS/JS的价值高很多,但我们都知道他们都是建立在HT ...