FatMouse' Trade

http://acm.hdu.edu.cn/showproblem.php?pid=1009

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35250    Accepted Submission(s): 11553

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
 
Author
CHEN, Yue
 
Source
 
 #include <stdio.h>

 typedef struct ST
{
int j;
int f;
double t;
}ST;
ST s[]; int cmp(const void *a,const void *b)
{
return (*(ST *)a).t > (*(ST *)b).t ? : -;
} int main()
{
int m,n;
while(scanf("%d %d",&m,&n),(m!=-&&n!=-))
{
int i,j;
int num;
double sum=;
for(i=;i<n;i++)
{
scanf("%d %d",&s[i].j,&s[i].f);
s[i].t = s[i].j*1.0/s[i].f;
}
qsort(s,n,sizeof(s[]),cmp);
num=m;
for(i=n-;i>=;i--)
{
if(num>s[i].f)
{
sum+=s[i].j;
num-=s[i].f;
}
else
{
sum+=s[i].t * num;
num=;
}
if(num==)
break;
}
printf("%.3lf\n",sum);
}
return ;
}

hdu_1009_FatMouse' Trade_201310280910的更多相关文章

  1. HDU_1009_FatMouse' Trade

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

随机推荐

  1. markdownpad2下载安装教程

    1.下载安装 http://markdownpad.com/download/markdownpad2-setup.exe 直接下载,安装过程中提醒要安装微软的一个什么环境,不用理会直接跳过,实测没有 ...

  2. SpringBoot 热部署 + IDEA

    1.使用Spring-Boot-Devtools实现热加载(这种方式会自动重启) devtools的原理: 深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类( ...

  3. 343 Integer Break 整数拆分

    给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积.例如,给定 n = 2,返回1(2 = 1 + 1):给定 n = 10,返回36(10 = 3 ...

  4. 协程概念,原理及实现(c++和node.js实现)

    协程 什么是协程 wikipedia 的定义: 协程是一个无优先级的子程序调度组件,允许子程序在特点的地方挂起恢复. 线程包含于进程,协程包含于线程.只要内存足够,一个线程中可以有任意多个协程,但某一 ...

  5. win32之bitmap篇

    先讲一下LoadBitmap的用法,代码如下: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); HDC hMemDC = CreateCompa ...

  6. win32窗口映射(部分)

    先理解一下“窗口”与“视区”的概念.“窗口”是逻辑坐标下的矩形区域,“视区”是设备坐标系下的区域.根据“窗口”和“视区”的大小可以确定x方向和y方向的比例因子. 例子如下: VOID OnPaint( ...

  7. 使用TFS創建團隊項目

    使用微軟賬號登錄Team Service,關聯一個TS賬戶,用來存放你所有的項目,可以從瀏覽器中直接訪問,地址類似yourname.visualstudio.com. 詳細鏈接 在TS賬戶主面板中,可 ...

  8. 错误处理:vmware下克隆centos7配置静态ip地址网卡问题

    vmware下克隆centos7,在配置静态ip地址,重启网卡存在问题,还是mac地址问题 ip addr show 查看下mac地址,配置文件修改下,重启网卡正常了

  9. js >> 右移操作符

    十进制 十六进制 二进制 右移>> 十进制值 F 1F FF

  10. CAD导出黑白色的pdf(com接口)

    主要用到函数说明: IMxDrawModifyTheColor 接口 用来修改图面所有对象的颜色,把它的颜色都修改成一个指定的值. IMxDrawModifyTheColor::Do 修改颜色,详细说 ...