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. django中怎样生成非HTML格式的内容。

    某些时候可能有这种需求.在网页中点击一个链接或者一个button希望返回一张图片.一个pdf文档.一个csv文档等而非HTML. 在diango中非常easy做到这些.django中的view用来接收 ...

  2. C#XML操作详解

     添加引用 using System.Xml; 创建XML文件 XmlDocument xmldoc=new XmlDocument(); //加入XML的声明段落:<?xmlversion=& ...

  3. c++标准库函数equal_range()

    首先容器(vector)的中的元素是有序的.这里就不讲容器元素类型为内置的类型的用法,因为比较容易. 重点讲一下容器元素类型为自定义类型时的用法.当我们把自定义类型的数据成员的类型的值传给equal_ ...

  4. ajax防止重复提交请求1

    ajax防止重复提交请求 A. 独占型提交 只允许同时存在一次提交操作,并且直到本次提交完成才能进行下一次提交. module.submit = function() {   if (this.pro ...

  5. Iso language code table之(软件国际化)

    ISO 639是用来区分所有已知的语言规范的术语.每种语言都分配两个字母(639-1)或三个英文字母(639-2和639-3),小写字母的缩写,修订后的版本命名的.该系统是非常有用的语言学家和人类学家 ...

  6. php的页面缓存练习

    <?php /* * 自定义页面缓存类 */ namespace page_cache; class Page { public $CacheRoot = "pageCache/&qu ...

  7. [LeetCode]题解(python):148-Sort List

    题目来源: https://leetcode.com/problems/sort-list/ 题意分析: 用nlog(n)的时间复杂度实现一个链表的排序. 题目思路: 用归并排序的思想,将链表用快慢指 ...

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

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

  9. rownum的使用-分页

    rownum的使用-分页 oracle分页显示方法 一.使用rownum分页显示方式 方式1:SELECT *  FROM (SELECT ROWNUM r, a.* FROM b$i_exch_in ...

  10. SQLServer2012 和 MariaDB 10.0.3 分页效率的对比

    1. 实验环境      R910服务器, 16G内存 SqlServer 2012   64bit MariaDB 10.0.3   64bit  (InnoDB) 2. 实验表情况 rtlBill ...