贪心_简单直接贪心[优先队列](HDU_1009)
2013-08-15 09:57
393 查看
#include <stdio.h> #include <string.h> #include <queue> using namespace std; #define M 1002 struct node { int j,f; node(int _j,int _f) { j = _j; f = _f; } friend bool operator < (const node a,const node b) { return 1.0 * a.j / a.f < 1.0 * b.j / b.f; } }; priority_queue<node> q; int main(int argc, char* argv[]) { #ifdef __MYLOCAL freopen("in.txt","r",stdin); #endif int m,n,Ji,Fi; double s; while(scanf("%d%d",&m,&n) + m + n) { while(!q.empty()) { q.pop(); } while(n--) { scanf("%d%d",&Ji,&Fi); q.push(node(Ji,Fi)); } s = 0; while(m > 0 && !q.empty()) { if(m >= q.top().f) s += q.top().j; else s += 1.0 * m / q.top().f * q.top().j; m -= q.top().f; q.pop(); } printf("%.3lf\n",s); } return 0; }
相关文章推荐
- 贪心_简单直接贪心(HDU_1009)
- HDU 5360——Hiking——————【贪心+优先队列】
- hdu 1789 Doing Homework again【贪心 || 贪心+优先队列】
- HDU 2187 简单贪心--直接排序
- HDU 1009:FatMouse' Trade(简单贪心)
- HDU 1009:FatMouse' Trade(简单贪心)
- HDU 6000 Wash (优先队列-贪心)
- HDU--杭电--1026--Ignatius and the Princess I--广搜--直接暴力0MS,优先队列的一边站
- 【简单贪心+优先队列】POJ - 1862 - Stripies
- Canada Cup 2016 D. Contest Balloons 好题。优先队列 + 简单贪心
- HDU--杭电--1026--Ignatius and the Princess I--广搜--直接暴力0MS,优先队列的一边站
- HDU 1873 看病要排队(优先队列的简单应用)
- hdu 5242 正解树链剖分,我的优先队列贪心
- hdu 1009 简单贪心
- 【HDU】5859 Captain is coding【优先队列贪心】
- HDU 5289 Assignment [优先队列 贪心]
- hdu 4544 湫湫系列故事——消灭兔子 贪心+优先队列 解题报告
- HDU 5360 【优先队列+贪心】
- hdu1009 优先队列
- hdu1009 nyoj824 FatMouse' Trade 简单贪心