FatMouse' Trade(杭电1009)

时间:2023-02-15 22:33:04

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&&num;39&semi; Trade (贪心)

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

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

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

  3. hdu 1009 FatMouse&amp&semi;&num;39&semi; Trade

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

  4. ZOJ 2109 FatMouse&amp&semi;&num;39&semi; Trade (背包 dp &plus; 贪婪)

    链接: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. NSString和NSMutableString常用方法&plus;NSArray常用代码 &lpar;转&rpar;

    常见的NSString和NSMutableString方法: NSString方法: [plain] view plaincopy   +(id) stringWithContentsOfFile:p ...

  2. openLDAP

    错误提示: D:\OpenLDAP>slapd -d 256 515a48ae OpenLDAP 2.4.34 Standalone LDAP Server (slapd)515a48af co ...

  3. &lbrack;UVA11464&rsqb;Even Parity(状压,枚举)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  4. Table of Contents - Nginx

    Downloading and  Installing Nginx Nginx for Windows Basic Nginx Configuration Configuration File Syn ...

  5. Dapper 基础用法

    Dapper是.Net下的一个简单orm框架,具有以下特点: 1.简单,只需要一个文件即可(SqlMapper.cs) 2.快速,下面是一个查询结果集在500以上的运行速度对比 3.不要求特定的db ...

  6. win8&period;1镜像制作

    使用自带的powerShell工具,以管理员身份运行,比如镜像的目标位置为F盘,那么用下面的命令即可, wbAdmin start backup -backupTarget:F: -include:C ...

  7. &lbrack;APIO2012&rsqb;

    来自FallDream的博客,未经允许,请勿转载,谢谢. --------------------------------------------------- A.dispatching 派遣 上次 ...

  8. 逆元知识普及&lpar;进阶篇&rpar; ——from Judge

    关于一些逆元知识的拓展 刚艹完一道 提高- 的黄题(曹冲养猪) ,于是又来混一波讲解了 ——承接上文扫盲篇   四.Lucas定理(求大组合数取模)   题外话 这里Lucas定理的证明需要用到很多关 ...

  9. C&num;防盗链处理类的代码

    如下的内容是关于C#防盗链处理类的内容. public class FileHandler:IHttpHandler{public FileHandler(){} public void Proces ...

  10. spring boot&lpar;二)web综合开发

    上篇文章介绍了Spring boot初级教程:spring boot(一):入门,方便大家快速入门.了解实践Spring boot特性:本篇文章接着上篇内容继续为大家介绍spring boot的其它特 ...