HDU 1009 FatMouse' Trade
2014-08-20 16:05
274 查看
忽然发现HDU上还有一道残留的没A过去的水题,那是当年年轻的我太菜了(现在依然很菜)。
简单的贪心,因为老鼠可以用猫粮等比例的换取每个房间里的Java豆,所以我们先换汇率高的,再换汇率低的。
代码君
简单的贪心,因为老鼠可以用猫粮等比例的换取每个房间里的Java豆,所以我们先换汇率高的,再换汇率低的。
//#define LOCAL #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1000 + 10; struct Trade { double f, j; }trade[maxn]; bool cmp(Trade a, Trade b) { return (a.j*b.f > a.f*b.j); } double ans, tot; int n; int main(void) { #ifdef LOCAL freopen("1009in.txt", "r", stdin); #endif while(scanf("%lf%d", &tot, &n) == 2) { if(n == -1) break; for(int i = 0; i < n; ++i) scanf("%lf%lf", &trade[i].j, &trade[i].f); sort(trade, trade + n, cmp); int i = 0; ans = 0; while(tot > 0 && i < n) { if(tot >= trade[i].f) { ans += trade[i].j; tot -= trade[i++].f; } else { ans += tot * trade[i].j / trade[i].f; tot = 0; } } printf("%.3lf\n", ans); } return 0; }
代码君
相关文章推荐
- Hdu 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- [ACM_HDU_1009]FatMouse' Trade(贪心算法入门)
- Hdu 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade【贪心】
- hdu_1009_FatMouse' Trade_201310280910
- HDU 1009 FatMouse' Trade 贪心题
- HDU 1009 FatMouse' Trade (贪心算法)
- HDU1009——FatMouse' Trade
- HDU 1009 - FatMouse' Trade
- hdu 1009 FatMouse' Trade(DP)
- HDU_1009_FatMouse' Trade
- FatMouse' Trade http://acm.hdu.edu.cn/showproblem.php?pid=1009
- hdu 1009 FatMouse' Trade(贪心)
- hdu-1009-FatMouse' Trade
- 【HDU 1009】FatMouse' Trade
- HDU 1009 FatMouse' Trade(贪心)
- HDU 1009 FatMouse' Trade肥老鼠的交易(AC代码) 贪心法