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. File类常见方法

    package file; import java.io.File; public class FileTest2 { public static void main(String[] args) { ...

  2. 我的Python成长之路---第二天---Python基础(8)---2016年1月9日(晴)

    数据类型之字典 一.字典简介 字典dict(dictionary),在其他语言中也成为map,使用键-值(key-value)的形式存储和展现,具有极快的查找速度. 字典的定义 d = {'key': ...

  3. two sets of Qt binaries into the same process的解决办法

    突然出现了这样问题,吓死我,然后只是把原来编译好的app里面所有的东西删除再编译就好了. 如果删除后不行,可以试试后面的截图所说,反正我是没有试过的 Starting /Qtwork/build-te ...

  4. maven本地jar

    <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId&g ...

  5. android模拟器 一个错误:X Error of failed request: BadRequest (invalid request code or no such operation)

    最近ubuntu12.04学习python,python2.7 python3.2所不同的是还是蛮大的.学习思考的新 升级后 结果显示 输入方法不显示   update-manager 和  add- ...

  6. 《Javascript权威指南》学习笔记之十二:数组、多维数组和符合数组(哈希映射)

    Array(数组)是JavaScript中较为复杂的数据类型,同Java.C#.VB等程序语言的数组相比.Javascript数组中的元素不必为同样的数据类型,能够在数组每一个元素上混合使用数字.日期 ...

  7. 将表中null值替换成想要的值、查询某一列值为null

    用到ISNULL()函数 例如:SELECT 其他列名,ISNULL(列名,替换值)as 重命名  from 表名 (简单参考:http://www.cnblogs.com/netsa/archive ...

  8. 遭遇“HTTP 错误 500.19 无法访问请求的页面,因为该页的相关配置数据无效。”

    windows 2008下IIS7 安装ASP.NET 遇到如下错误: HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. ...

  9. BZOJ 2693: jzptab( 莫比乌斯反演 )

    速度居然#2...目测是因为我没用long long.. 求∑ lcm(i, j) (1 <= i <= n, 1 <= j <= m) 化简之后就只须求f(x) = x∑u( ...

  10. How to configure CDB in Qt Creator(使用VC调试器)

    I was having the same problems too, and finally figured out how to solve this. Styne666 gave me a hi ...