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. android通过服务实现消息推送

    这里运用到的andorid知识模块主要有Notification和Service,和一个android-async-http-master开源框架 android项目中,有时会有这样一种需求:客户每隔 ...

  2. JavaScript DOM省市自适配select菜单

    <html> <head> <meta charset="UTF-8"> <meta name="Generator" ...

  3. Git 文件状态的转换

    很好低使用git 文件的状态转换的了解是非常重要的. 文件转换状态其实可以分为四种: untracked:未跟踪,此文件在工作区中,但并没有加入git库,不参与版本控制. 通过”git add”,”g ...

  4. POJ 3304 Segments(计算几何)

    意甲冠军:给出的一些段的.问:能否找到一条直线,通过所有的行 思维:假设一条直线的存在,所以必须有该过两点的线,然后列举两点,然后推断是否存在与所有的行的交点可以是 代码: #include < ...

  5. 梳理一下uboot是如何从nandflash挂载文件系统的

    只是找到了比较一点点的线索, 如下: 首先要有的概念是,内核在挂载文件系统之前,自己会做一个虚拟fs. 1. Uboot:从flash启动set bootcmd nand read 0x3000000 ...

  6. linux: Ubuntu安装samba的问题

    Ubuntu安装samba的问题 http://blog.csdn.net/jk110333/article/details/8920841 root@ubuntu:~# apt-get instal ...

  7. wcf 出现 IsContentTypeSupported 错误

    查看添加的服务地址是不是https开头的,而 *.config 文件里面自动添加的链接变成了http,当前的bindbing类型为basicHttpBinding, 解决方法:在config文件里面手 ...

  8. js和循环依赖

    kmdjs和循环依赖 循环依赖是非常必要的,有的程序写着写着就循环依赖了,可以提取出一个对象来共同依赖解决循环依赖,但是有时会破坏程序的逻辑自封闭和高内聚.所以没解决好循环依赖的模块化库.框架.编译器 ...

  9. 类作为返回类型 ,具有java特点-封装等 而且应用起来很方便。

    public class StudentDao { public Student getStudent(){ Student stu = new Student(); stu.setName(&quo ...

  10. HTML+CSS - 搜索 And 高级搜索