这题是一道简单的可拆分的贪心题目,需要注意的是,我们定义的结构体里面都应该用double类型, 或者float类型,不然两个int相除,就失去了精度(强转也可以)。

#include <cstdio>
#include <algorithm>
using namespace std;
int m, n;
struct Room {
double j, f;
double k;
bool operator < (const Room &b)const {
return k > b.k;
}
} a[1000]; int main()
{
while (scanf("%d%d",&m,&n)&&m!=-1&&n!=-1) {
for (int i = 0; i < n;i++) {
scanf("%lf%lf", &a[i].j, &a[i].f);
a[i].k = a[i].j / a[i].f;
}
sort(a, a + n);
double pock=0, value=0;
for (int i = 0; i < n; i++) {
if (pock+a[i].f<m) {
value += a[i].j;
pock += a[i].f;
}
else {
value += (a[i].j / a[i].f) * (m - pock);
break;
}
}
printf("%.3lf\n", value);
}
return 0;
}

HDU-1009-肥鼠交易的更多相关文章

  1. HDU 1009 FatMouse' Trade (贪心)

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

  2. HDU 1009 FatMouse' Trade肥老鼠的交易(AC代码) 贪心法

    题意: 一只老鼠用猫粮来换豆子,每个房间的兑换率不同,所以得尽量从兑换率高的房间先兑换.肥老鼠准备M磅猫粮去跟猫交易,让猫在warehouse中帮他指路,以找到好吃的.warehouse有N个房间,第 ...

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

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

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

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

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

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

  6. HDU 1009 FatMouse' Trade(贪心)

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

  7. HDU 1009:FatMouse&#39; Trade(简单贪心)

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

  8. Hdu 1009 FatMouse' Trade

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

  9. 贪心算法 hdu 1009

    1.因为要排序只派j[i]/f[i],不能知道f[i]和j[i]各自排序后的顺序,因此要用到结构体 2.用sort(ware,ware+n,cmp) cmp 为俩个数组的元素比较大小的布尔值 #inc ...

  10. 【HDU 1009】FatMouse' Trade

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

随机推荐

  1. iOS 7 隐藏特性

    当 iOS7 刚发布的时候,全世界的苹果开发人员都立马尝试着去编译他们的app,接着再花上数月的时间来修复任何出现的故障,甚至重做app.这样的结果,使得人们根本无暇去探究 iOS7 所带来的新东西. ...

  2. 如何找出nginx配置文件的所在位置?

    对于一台陌生的服务器或安装太久忘了位置,怎么才能简单快速的找到配置文件的位置呢?要找出配置文件的位置,需要先找出nginx可执行文件的路径 , 这里有几种方法: 1.如果程序在运行中 ps -ef | ...

  3. (转)java 线程同步

    转自 http://blog.csdn.net/column/details/java-thread.html http://leo-faith.iteye.com/blog/177779 http: ...

  4. luoguP3808[模板]AC自动机(简单版)

    传送门 ac自动机模板题,裸的多串匹配 代码: #include<cstdio> #include<iostream> #include<algorithm> #i ...

  5. 51nod 1562 玻璃切割 (set)

    #include<stdio.h> #include<iostream> #include<set> using namespace std; typedef lo ...

  6. SVN有任何胜过git的地方吗?

    SVN有任何胜过git的地方吗? 好的技术问题通常会引出技术专家们依据经验得出的深层次的观点.但对于这样的问题的答案也很容易演变成完全基于个人喜好的情绪倾泄,而不是根据事实.标准和具体的专业知识.就比 ...

  7. __next__,__iter__实现迭代器,斐波那契数列

    迭代器__next__,__iter__ 基于__next__和__iter__方法实现的迭代器 class Foo: def __init__(self,n): self.n = n def __i ...

  8. [POI2011]Plot

    https://szkopul.edu.pl/problemset/problem/mzrTn1kzVBOAwVYn55LUeAai/site/?key=statement 既卡常又卡精度...真的A ...

  9. js中对象的理解

    JS中对象是可变的控件集合,对象的内容是可以更改的,可以为它添加任意属性或删除,而基本数据类型虽然拥有方法,但它们的值是不可变的,之所以它们拥有方法,是因为当它们调用方法是,后台会自动创建一个相映包装 ...

  10. django modelform中的self.instance

    在stackoverflow上看到一个问题,正好是我疑惑很久的相关问题. [原问题地址]https://stackoverflow.com/questions/18265023/self-instan ...