FatMouse' Trade





Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 41982    Accepted Submission(s): 13962

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

题意就是老鼠用猫粮换鼠粮。

。(Orz)。。

求它最多能换多少。。一道贪心水题。


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath> #define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, n) for(int i=1; i<=n; i++) using namespace std; const int M = 1005;
int n, m;
double ans;
double t; struct node
{
double J;
double F;
double c;
}Q[M]; int cmp (node a, node b)
{
return a.c > b.c;
} int main()
{
while(scanf("%d%d", &n, &m)!=EOF)
{
ans = 0;
t = (double) n;
memset(Q, 0, sizeof(Q));
if(n==-1 && m==-1)
break;
f1(i, m)
{
scanf("%lf%lf", &Q[i].J, &Q[i].F);
Q[i].c = Q[i].J / Q[i].F;
}
sort(Q, Q+m, cmp);
f1(i, m)
{
if( Q[i].F<=t )
{
ans += Q[i].J;
t -= Q[i].F;
}
else
{
ans += t * Q[i].c;
break;
}
}
printf("%.3lf\n", ans);
} return 0;
}

HDU 1009:FatMouse&#39; Trade(简单贪心)的更多相关文章

  1. hdu 1009 FatMouse&#39; Trade

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

  2. HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  3. HDU 1009 FatMouse' Trade(简单贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  4. FatMouse&#39; Trade(杭电1009)

    FatMouse' Trade Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  5. 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 ...

  6. [题解]hdu 1009 FatMouse' Trade(贪心基础题)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  7. HDU 1009 FatMouse' Trade (贪心)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009 题目大意:肥鼠准备了 磅的猫粮,准备和看管仓库的猫交易,仓库里装有他最喜爱的食物 豆.仓库有 个 ...

  8. HDU 1009 FatMouse' Trade(贪心)

    FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...

  9. hdu 1009:FatMouse' Trade(贪心)

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

随机推荐

  1. (6)python 循环控制

    一.if语句 1.条件执行和if语句 2.else子句 3.elif子句 多个检查条件时 4.嵌套代码  5.空语句 使用pass占位 6.断言 关键字 assert 判断表达式前加上这个关键字表示, ...

  2. HDU 1236 排名(结构体+排序)

    今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑 每题的分值,所以并不是最后的排名.给定录取分数线,请你写程序找出最后通过分数线的 考生,并将他们的成绩按降序打 ...

  3. cnblogs的代码高亮

    由于不喜欢cnblogs原来的代码高亮方案,于是自己瞎搞,外加看这位大神的blog以及BZOJ的代码高亮,终于是搞出来了...讲讲怎么弄吧. 当然对于了解css的大神可以无视以下文字…… 其实就是登上 ...

  4. css中width和height默认值

    width和height默认都是auto自动伸缩的,但不同的标签效果却不一样比如div默认是width:100%,通常不用写100%如果是table,如果div内的table没有设定100%,那就是最 ...

  5. 理解Android绘制视图的方式

    在创建自定义ViewGroup前,读者首先需要理解Android绘制视图的方式.我不会涉及过多细节,但是需要读者理解Android开发文档(见3.5节)中的一段话,这段话解释如何绘制一个布局.内容如下 ...

  6. RxJava 1.x 理解-1

    先看下别人实现的最基本的RxJava的实现方式: 在RxJava里面,有两个必不可少的角色:Subscriber(观察者) 和 Observable(订阅源). Subscriber(观察者) Sub ...

  7. Klaus Aschenbrenner--windbg

    http://www.sqlservercentral.com/blogs/aschenbrenner/?page=1

  8. display:flex;多行多列布局学习

    从以前的table布局到现在的div布局,再到未来的flex布局,CSS重构方面对展示行和适应性的要求越来越高: 首先来比较一下布局方式的更新意义: table布局: 优点:1.兼容性好,ie6.ie ...

  9. 【java】子类可以通过调用父类的public方法调用父类的private方法,为什么?

    代码1: 打印结果: 代码2: 运行结果: 问题: 代码1中super是父类自己调用自己的add()方法,并在add()方法中调用了私有的del()方法,那为什么打印出来的this是子类? 代码2中t ...

  10. RabbitMq_05_Topics

    Topics (using the .NET client) Prerequisites This tutorial assumes RabbitMQ isinstalled and running ...