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. windows 7系统下安装SQL Server 2005图文教程

    由于工作需要,今天要在电脑上安装SQL Server 2005.以往的项目都是使用Oracle,MS的数据库还真的没怎么用过,安装Oracle已经轻车熟路,但装SQL Server好像还有点小麻烦,所 ...

  2. 8.4 IP地址的划分及子网划分

    都是比较灵活的一些计算题.只要掌握了其中的规则,还是比较容易解题的.在了解子网的划分如何进行之前呢,一定要弄清楚一个概念:子网掩码.这是弄清楚如何进行子网划分的一个关键. IP地址是四段二进制码拼合而 ...

  3. ORA-01012:not logged on的解决办法

    conn / as sysdba 报错ORA-01012: not logged on 发生原因:关闭数据库是shutdown 后面没有接关闭参数中的任何一个. nomal ————- —-所有连接都 ...

  4. C++ 由虚基类 虚继承 虚函数 到 虚函数表

    //虚基类:一个类可以在一个类族中既被用作虚基类,也被用作非虚基类. class Base1{ public: Base1(){cout<<"Construct Base1!&q ...

  5. 入门开发工具idea常见问题之选项中没有servlet

    1.在maven中如果创建不了servlet,在project Setting旁边的添加一个web选项,就可以创建servlet了. 初次接触这个陌生的工具还是不太好弄.

  6. java中使用String的replace方法替换html模板保存文件

    在我们的D盘下有这样一个html模板,现在我们要做的就是解析news.template文件,从数据库中提取数据将数据添加到指定的模板位置上 <head> <title>{tit ...

  7. 使用XUL开发跨平台桌面应用

    先上图: 现在使用html,css,js开发桌面的优势越来越明显了,硬件性能的不断提升,人力成本越发昂贵,用户对界面要求越来越高,全球化下企业间的竞争越发激烈. 桌面软件50%+的工作量都在界面开发这 ...

  8. Gradle的属性Property设置与调用

    Gradle在默认情况下已经为Project定义了很多Property: project:Project本身 name:Project的名字 path:Project的绝对路径 description ...

  9. Linux下的文件结构,及对应文件夹的作用

    Linux下的文件结构,及对应文件夹的作用 /bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基点,比 ...

  10. RTL Compiler之Technology Library

    1 Target Library Design Compiler uses the target library to build a circuit. During mapping, Design ...