POJ 3614

来源:互联网 发布:box2d python 编辑:程序博客网 时间:2024/06/03 18:17

题目大意:

共有C头牛,为了使其更好的工作,需要给它涂上防晒霜。牛所能承受的阳光强度各不相同,处于一个区间。而防晒霜是能固定一个温度,如果这个温度处于牛的承受区间内,则适合此牛使用,否则不适合。

其中,防晒霜共有L中,每种有 i 瓶。

我的理解:

此处我借鉴了此人 的思想;

贪心+优先队列;

我的代码:

#include <iostream>#include <cstdio>#include <queue>#include <vector>#include <algorithm>#define MAX_N 2505using namespace std;typedef pair<int,int> P;priority_queue<int, vector<int>, greater<int> > que; int C,L;P cow[MAX_N],bot[MAX_N];int main(){freopen("D:/OJ/挑战程序设计竞赛/POJ3614.txt","r",stdin);const int INF = 1000000000;int j = 0;int result = 0;cin>>C>>L;for(int i = 0;i<C;i++){cin>>cow[i].first>>cow[i].second;}for(int i = 0;i<L;i++){cin>>bot[i].first>>bot[i].second;}sort(cow,cow+C);sort(bot,bot+L);for(int i = 0;i<L;i++){while(j<C && cow[j].first <= bot[i].first){que.push(cow[j].second);j++;}while(!que.empty() && bot[i].second){int x = que.top();que.pop();if(x< bot[i].first)continue;result++;bot[i].second--;} }cout<<result<<endl;return 0;} 

原创粉丝点击