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. 动画原理——脉动(膨胀缩小)&&无规则运动

    书籍名称:HTML5-Animation-with-JavaScript 书籍源码:https://github.com/lamberta/html5-animation 1.脉动是一种半径r来回反复 ...

  2. 修改AspNetSqlMembershipProvider的密码规则

    在AspNetSqlMembershipProvider中,默认的密码规则为长度大于等于7,并且包含1个除字母和数字外的特殊字符,这项规则主要由minRequiredPasswordLength和mi ...

  3. 文件和文件夹权限-Win7公共盘中出现大量临时文件

    公司中有一个文件服务器,给不同部门和员工设置了不同的权限,最近有员工(没有修改权限,有读取及执行,读取,写入)反映在公共盘上修改文件的时候会产生大量的临时文件,添加上修改权限之后就可以了,然后被同事问 ...

  4. Android 开源库

    http://www.cnblogs.com/hawkon/p/3593709.html

  5. webview与JavaScript之间的交互

    据说WebView的强大之处就是能和JavaScript进行交互调用. 参考博客:http://droidyue.com/blog/2014/09/20/interaction-between-jav ...

  6. Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool

    原因:缺少commons-pool-X.jar包,到http://commons.apache.org/proper/commons-pool/download_pool.cgi下载后引入即可(地址可 ...

  7. Oracle的实例占用内存调整

           1.操作 (oracle使用内存约等于 SGA+PGA,所以可以减少SGA与PGA解决你的问题,生产库慎用)alter system set sga_max_size=100m scop ...

  8. EC读书笔记系列之8:条款13、14、15

    条款13 以对象管理资源 记住: ★为防止资源泄漏,请使用RAII对象,它们在构造函数中获得资源并在析构函数中释放 ★两个常被使用的RAII classes分别是tr1::shared_ptr和aut ...

  9. 已经包含了#include <atlcom.h> #include <comutil.h>还是报错

    在WTL工程的.h中 #include <atlbase.h>#include <atlcom.h>#include <atlcomcli.h>#include & ...

  10. python 32位、64位确定

    1.python 进入交互式命令行,如下: 2.执行以下命令: import struct;print struct.calcsize("P") * 8