标签:
按照截止日期排序,之后一个一个遍历,记录当前时间,如果当前时间大于截止时间,那么从选过的任务里删除一个花费最大的任务
优先队列维护
14038525 | 201301052100 | 2786 | Accepted | 11168K | 1016MS | C++ | 905B | 2015-04-02 12:22:16 |
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<vector> using namespace std; struct Node{ int a,b; Node(int a,int b):a(a),b(b){}; friend bool operator < (Node p,Node q){ return p.a < q.a; } }; bool cmp(Node p,Node q){ return p.b < q.b; } int n; int main(){ while(scanf("%d",&n) != EOF){ vector<Node>v; priority_queue<Node>q; for(int i = 0; i < n; i++){ int a,b; scanf("%d%d",&a,&b); v.push_back(Node(a,b)); } int now = 0; sort(v.begin(),v.end(),cmp); for(int i = 0; i < v.size(); i++){ q.push(v[i]); now += v[i].a; if(now > v[i].b){ now -= q.top().a; q.pop(); } } printf("%d\n",q.size()); } return 0; }
【POJ】2786-Keep the Customer Satisfied(贪心 + 优先队列,姿势不对就要跪)
标签:
原文地址:http://blog.csdn.net/u013451221/article/details/44830467