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. java网络编程UDP

    图片来自网络 [发送端] import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSoc ...

  2. E20171028-hm

    stick   n. 棍棒,棍枝; 枝条; 操纵杆; 球棍; stopwatch  n. (赛跑等记时用的) 秒表,跑表; agency   n. 代理; 机构; 力量; various   adj. ...

  3. 产生冠军(toposort)

    http://acm.hdu.edu.cn/showproblem.php?pid=2094 #include <stdio.h> #include <iostream> #i ...

  4. bzoj2730矿场搭建(Tarjan割点)

    2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1771  Solved: 835[Submit][Statu ...

  5. 聊聊 webpack 打包如何压缩包文件大小

    想必很多人都经历过做完一个项目后,再打包发现某些文件非常大,导致页面加载时很慢,这就很影响用户体验了,所以在我经历了一些打包后,讲讲如何有效地缩小包体积,加快页面的首屏渲染 动态 polyfill 相 ...

  6. Java 删除List元素的正确方式

    方式一:使用Iterator的remove()方法 public class Test { public static void main(String[] args) { List<Strin ...

  7. 使用Jupter Notebook实现简单的神经网络

    参考:http://python.jobbole.com/82208/ 注:1)# %matplotlib inline 注解可以使Jupyter中显示图片 2)注意包的导入方式 一.使用的Pytho ...

  8. JS——正则

    正则的声明: 1.构造函数:var 变量名= new RegExp(/表达式/); 2.直接量:var 变量名= /表达式/; test()方法: 1.正则对象方法,检测测试字符串是否符合该规则,返回 ...

  9. JS——行内式注册事件

    html中行内调用function的时候,是通过window调用的function,所以打印this等于打印window,所以在使用行内注册事件时务必传入参数this <!DOCTYPE htm ...

  10. MyEclipse快捷键 (精简)

    在调试程序的时候,我们经常需要注释一些代码,在用Myeclipse编程时,就可以用 Ctrl+/ 为选中的一段代码加上以 // 打头的注释:当需要恢复代码功能的时候,又可以用Ctrl+/ 去掉注释.这 ...