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
 

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct p
{
double a;
double b;
double c;
};
bool compare(p A,p B)
{
return A.c>B.c;
}
int main()
{
int m,n,i,j;
while(scanf("%d%d",&m,&n)!=EOF)
{
if(m==-1&&n==-1)
break;
p t[1001];
for(i=0;i<n;i++)
{
cin>>t[i].a>>t[i].b;
t[i].c=t[i].a/t[i].b;
}
sort(t,t+n,compare);
double count=0;
for(i=0;i<n;i++)
{
count+=t[i].b;
if(count>m)
break;
}
double sum=0;
//if(i==0)
//printf("%.3lf\n",t[0].c*m);
if(count<m)
{
for(j=0;j<n;j++)
sum+=t[j].a;
printf("%.3lf\n",sum);
}
else
{
for(j=0;j<i;j++)
{
sum+=t[j].a;
m-=t[j].b;
}
printf("%.3lf\n",sum+m*t[i].c);
}
}
return 0;
}
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int m,n;
int i,j;
double a[1002],b[1002];
double c[1002];
while(scanf("%d%d",&m,&n)!=EOF)
{
if(m==-1&&n==-1)
break;
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
c[i]=a[i]/b[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(c[j+1]>c[j])
{
swap(b[j],b[j+1]);
swap(a[j],a[j+1]);
swap(c[j],c[j+1]);
}
}
}
double count=0;
for(i=0;i<n;i++)
{
count+=b[i];
if(count>m)
break;
}
double sum=0;
if(count<m)
{
for(j=0;j<n;j++)
sum+=a[j];
printf("%.3lf\n",sum);
}
else
{
for(j=0;j<i;j++)
{
sum+=a[j];
m-=b[j];
}
printf("%.3lf\n",sum+m*c[i]);
}
}
return 0;
}

A - FatMouse' Trade的更多相关文章

  1. Hdu 1009 FatMouse' Trade

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

  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 分类: 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) ...

  4. 1009 FatMouse' Trade

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

  5. FatMouse' Trade

    /* problem: FatMouse' Trade this is greedy problem. firstly:we should calculate the average J[i]/F[i ...

  6. HDU1009 FatMouse' Trade

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

  7. HDU 1009 FatMouse' Trade(贪心)

    FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...

  8. FatMouse' Trade -HZNU寒假集训

    FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...

  9. FatMouse' Trade(杭电ACM---1009)

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

  10. Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏

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

随机推荐

  1. C#反射的应用【转】

    摘要: 对于反射贫道也是很陌生的,所以趁现在有时间就把反射看了一下,记下笔记!!! 初始听说反射是可以动态的调用程序集,并从中来获取相应的方法和属性,感觉比较神奇,,, 反射的定义:反射(Reflec ...

  2. LDT自己定义启动模拟器

    近期使用LUA开发手游,团队里大神自研了个框架,底层C++渲染,上层LUA处理逻辑. LUA的IDE选择LDT,不爽的是它不能自己主动启动模拟器,看过COCOSIDE能自启动,于是我想改造下LDT让它 ...

  3. UNIX网络编程--读书笔记

    会集中这段时间写UNIX网络编程这本书的读书笔记,准备读三本,这一系类的文章会不断更新,一直会持续一个月多,每篇的前半部分是书中讲述的内容,每篇文章的后半部分是自己的心得体会,文章中的红色内容是很重要 ...

  4. [Phonegap+Sencha Touch] 移动开发36 Phonegap/Cordova项目的图标和启动画面(splashscreen)配置

    原文地址:http://blog.csdn.net/lovelyelfpop/article/details/40780111 Phonegap/Cordova项目中的config.xml文件.里面配 ...

  5. BZOJ 2186 SDOI2008 沙拉公主的困惑 数论

    题目大意:给定询问组数T和取模数P,每次询问给定两个整数n和m,求1~(n!)的数中与m!互质的数个个数模P (m<=n) 首先T<=1W,暴力肯定过不去,我们须要预处理一些东西 首先我们 ...

  6. werkzeug源码阅读笔记(二) 下

    wsgi.py----第二部分 pop_path_info()函数 先测试一下这个函数的作用: >>> from werkzeug.wsgi import pop_path_info ...

  7. asp.net mvc 注册中的邮箱激活功能实现(一)

    基本流程图 注册页面就不再写出,现在将发送邮件的代码粘贴出来 public ActionResult SendEmial() { ; string validataCode = System.Guid ...

  8. eclipse 打开文件目录

    用简单的配置方式 eclipse打开当前文件所在文件夹的插件 Run-->External Tools-->External Tools Configurations... new 一个 ...

  9. HTML知识点摘记

    HTML HTML:(Hype Text Markup Language)超文本标记语言,是最基本的网页语言.代码由标签组成,不区分大小写. 由<html>开始,</html> ...

  10. 退货行RMA编号改为必输选项

    应用 Oracle Inventory 层 Level Function 函数名 Funcgtion Name RCV_RCVTXERE 表单名 Form Name RCVTXERE 说明 Descr ...