【POJ 2970】The lazy programmer(优先队列+贪心)
2015-03-31 11:46
435 查看
这题范围不会超long long全用int存就行了
贪心的话,每次把一个任务加入到队列,如果不能在指定时间完成就到前面找a最小的一个任务补偿时间,当一个任务完成时间等于0的时候这个任务就不再放回队列
贪心的话,每次把一个任务加入到队列,如果不能在指定时间完成就到前面找a最小的一个任务补偿时间,当一个任务完成时间等于0的时候这个任务就不再放回队列
#include<cstdio> #include<queue> #include<algorithm> #include<cstring> using namespace std; //typedef long long LL; const int maxn = 100005; int n; struct Node{ int a,b; int d; Node(int a = 0,int b = 0,int d = 0):a(a),b(b),d(d){}; friend bool operator <(Node p,Node q){ if(p.a != q.a) return p.a < q.a; else return p.d < q.d; } }node[maxn]; bool cmp1(Node p,Node q){ return p.d < q.d; } int main(){ while(scanf("%d",&n) != EOF){ for(int i = 0; i < n; i++){ scanf("%d%d%d",&node[i].a,&node[i].b,&node[i].d); } sort(node,node + n,cmp1); priority_queue<Node>q; int sum = 0; double ans = 0.0; for(int i = 0; i < n; i++){ q.push(node[i]); sum += node[i].b; if(sum > node[i].d){ while(sum != node[i].d){ Node now = q.top(); q.pop(); int need = sum - node[i].d; //需要补偿的时间 if(now.b <= need){ ans += 1.0 * now.b / now.a; sum -= now.b; } else{ now.b -= need; ans += 1.0 * need / now.a; sum -= need; q.push(now); } } } } printf("%.2f\n",ans); } return 0; }
相关文章推荐
- POJ 2970 The lazy programmer(优先队列+贪心)
- POJ 2970 The lazy programmer(优先队列+贪心)
- POJ 2970 The lazy programmer(贪心+单调优先队列)
- poj 2970 The lazy programmer 优先队列
- Poj 2970 The lazy programmer(贪心)
- POJ 2970 The lazy programmer 优先队列
- POJ-2970-The lazy programmer
- POJ2970 The Lazy Programmer
- POJ 2970 The lazy programmer 优先队列
- poj 2786 Keep the Customer Satisfied(贪心+优先队列)
- SPOJ 417 The lazy programmer(优先队列)
- SPOJ 417 The lazy programmer(贪心)
- POJ 2431 Expedition (贪心 + 优先队列)
- POJ 2786 Keep the Customer Satisfied 优先队列
- POJ 2786 Keep the Customer Satisfied 优先队列
- POJ 2431 Expedition (优先队列+贪心)
- POJ 3253 Fence Repair(贪心,优先队列)
- poj 2287 Tian Ji -- The Horse Racing(贪心)
- poj 3253 Fence Repair (贪心+哈弗曼思想+优先队列)
- POJ(2761)Feed the dogs (树状数组+离散化+贪心)