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. PCB SQL SERVER 字段模糊匹配个数 实现方法

    今天工程系统给到加投加投组件的数据规则修改,遇到需将一个字段模糊匹配的个数统计 这类需求要平时应该很少遇到了,这里将此方法分享出来, 一.需求如下 例子:itempara字段中的内容是: IVH板 铜 ...

  2. 9.22 NOIP模拟题

    吉林省信息学奥赛 2017 冬令营                                                                                    ...

  3. [Swift通天遁地]四、网络和线程-(14)创建一个Socket服务端

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. 哈夫曼编码译码系统(c/c++)

    哈夫曼编码译码系统的实现,主要包含三部分: 1.创建哈夫曼树 2.编码函数 3.译码函数 编写代码时为了方便,在这里混用了c++的输入输出流.主体用c语言实现. 下面时代码部分: 1.头文件,以及储存 ...

  5. 【洛谷1654/BZOJ4318】OSU!(期望DP)

    题目: 洛谷1654 分析: 本人数学菜得要命,这题看了一整天才看明白-- 先说说什么是"期望".不太严谨地说,若离散型随机变量(可以看作"事件")\(X\)取 ...

  6. 题解报告:hdu 2516 取石子游戏(斐波那契博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2516 Problem Description 1堆石子有n个,两人轮流取.先取者第1次可以取任意多个, ...

  7. cms中某些标题链接的单独写法

    href="{$CATEGORYS[45][url]}" 链接写法, {$CATEGORYS[45][catname]} 标题写法 在show页面中 src="{$thu ...

  8. html5——3D案例(音乐盒子、百度钱包)

    1.音乐盒子:触碰盒子,盖子会打开 2.百度钱包:触碰钱包,钱包,会180度旋转 <!DOCTYPE html> <html lang="en"> < ...

  9. 转载:使用FileReader对象的readAsDataURL方法来读取图像文件

    文章转载自:http://blog.okbase.net/jquery2000/archive/1296.html: FileReader对象的readAsDataURL方法可以将读取到的文件编码成D ...

  10. js 获取 鼠标位置 和获取元素位置

    ]; body.addEventListener("mousemove", outpostion); function outpostion() { console.log(&qu ...