HDU 1009:FatMouse' Trade(简单贪心)
FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41982 Accepted Submission(s): 13962
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.
is followed by two -1's. All integers are not greater than 1000.
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
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' Trade(简单贪心)的更多相关文章
- hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- HDU 1009 FatMouse' Trade(简单贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- FatMouse' Trade(杭电1009)
FatMouse' Trade Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- 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 ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- HDU 1009 FatMouse' Trade (贪心)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009 题目大意:肥鼠准备了 磅的猫粮,准备和看管仓库的猫交易,仓库里装有他最喜爱的食物 豆.仓库有 个 ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- HDU3414 Tour Route(竞赛图寻找哈密顿回路)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3414 本文链接:http://www.cnblogs.com/Ash-ly/p/5459540.html ...
- 训练指南 UVALive - 5135 (双连通分量)
layout: post title: 训练指南 UVALive - 5135 (双连通分量) author: "luowentaoaa" catalog: true mathja ...
- noi 题库1.7字符串 第16至20题
16:忽略大小写的字符串比较 一般我们用strcmp可比较两个字符串的大小,比较方法为对两个字符串从前往后逐个字符相比较(按ASCII码值大小比较),直到出现不同的字符或遇到'\0'为止.如果全部字符 ...
- 第2天-css快速入门
css是什么 css(cascading style sheet,可以译为“层叠样式表”),是一组格式设置规则,用于控制web页面的外观 如何让一个标签具有样式 第一步:必须保证引入方式正确 第二步: ...
- 如何加快exp/imp的速度 - direct=y
http://blog.itpub.net/35489/viewspace-613625 Oracle9i 或 10g . 1. 内存中关系到exp的速度的是 large_pool_siz ...
- web前端读取文本文件内容
html5+js实现,参照xxyy888的CSDN博客文章<使用HTML+javascrpt读取txt文本文件>失败,将作者文章中的代码重新整理了下依然不行,文章代码存在的问题是括号错误, ...
- telnet执行过程及验证远程服务器是否打开
telnet执行过程: 工作原理: 当你用Telnet登录进入远程计算机系统时,你事实上启动了两个程序,一个 叫Telnet客户程序,它运行在你的本地机上:另一个叫Telnet服务器程序,它运 行在你 ...
- [ZOJ3522]Hide and seek
题意:给一棵带边权的树,多次询问$(x,y,l)$表示如果加一条连接$x$和$y$的长为$l$的边,所有点到$x$和到$y$的最短路减少了多少 先把题目中的图放上来(雾 考虑用lct维护,先把路径提出 ...
- 【记忆化搜索】bzoj1079 [SCOI2008]着色方案
#include<cstring> #include<cstdio> using namespace std; #define MOD 1000000007 typedef l ...
- Spark小问题合集
1)在win7下使用spark shell运行spark程序,通过以下形式读取文件时 sc.sequenceFile[Int,String]("./sparkF") 偶尔会出现“I ...