题意:m头牛每头牛有minspf和maxspf,n种spf为spf[i]的防晒霜每种l[i]瓶,尽可能给数量多的牛涂防晒霜,每头牛最多涂一瓶。

思路:贪心想法,实现是每次取出minspf<=spf[i]的牛加入优先队列中,优先队列以牛的maxspf为优先,给maxspf>=spf[i]且maxspf从小开始取的牛涂(优先队列)。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
pair<int,int> cow[];
pair<int,int> bot[];
struct cmp {
bool operator () (pair<int,int> a,pair<int,int> b) {
return a.second>b.second;
}
}; priority_queue<pair<int,int>,vector<pair<int,int> >,cmp> pq;
int main() {
int c,l,smin,smax,cnt=;
scanf("%d%d",&c,&l);
for(int i=;i<c;i++) {
scanf("%d%d",&cow[i].first,&cow[i].second);
}
sort(cow,cow+c);
for(int i=;i<l;i++) {
scanf("%d%d",&bot[i].first,&bot[i].second);
}
sort(bot,bot+l);
pair<int,int> temp;
int j=;
for(int i=;i<l;i++) {
while(j<c &&cow[j].first<=bot[i].first) {
pq.push(cow[j]);
j++;
}
while(bot[i].second> && !pq.empty()) {
temp=pq.top();
pq.pop();
if(temp.second>=bot[i].first) {
cnt++;
bot[i].second--;
}
}
}
printf("%d\n",cnt);
return ;
}

POJ3614 贪心+优先队列的更多相关文章

  1. hihoCoder 1309:任务分配 贪心 优先队列

    #1309 : 任务分配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN,  ...

  2. UVA 11134 - Fabled Rooks(贪心+优先队列)

    We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrict ...

  3. C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列

    C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  4. HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解

    思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...

  5. 贪心+优先队列 HDOJ 5360 Hiking

    题目传送门 /* 题意:求邀请顺序使得去爬山的人最多,每个人有去的条件 贪心+优先队列:首先按照l和r从小到大排序,每一次将当前人数相同的被邀请者入队,那么只要能当前人数比最多人数条件小,该人能 被邀 ...

  6. [POJ1456]Supermarket(贪心 + 优先队列 || 并查集)

    传送门 1.贪心 + 优先队列 按照时间排序从前往后 很简单不多说 ——代码 #include <queue> #include <cstdio> #include <i ...

  7. Painting The Fence(贪心+优先队列)

    Painting The Fence(贪心+优先队列) 题目大意:给 m 种数字,一共 n 个,从前往后填,相同的数字最多 k 个在一起,输出构造方案,没有则输出"-1". 解题思 ...

  8. CF140C New Year Snowmen(贪心+优先队列)

    CF140C 贪心+优先队列 贪心策略:每次取出数量最多的三种球,合成一个答案,再把雪球数都-1再插回去,只要还剩下三种雪球就可以不断地合成 雪球数用优先队列维护 #include <bits/ ...

  9. POJ3614 Sunscreen 优先队列+贪心

    Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...

随机推荐

  1. php rsa加密解密实例 及签名验证-自己实践

      <?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/4/1 * Time: 1:50 */ //注意格式一 ...

  2. Android开发系列之系统源码目录

    相信大家对于Google给出的那副经典Android架构图非常的熟悉,从下往上依次是Linux内核层(主要是负责硬件管理调度),HAL层(主要是硬件抽象层),libs层+Runtime,Framewo ...

  3. Android应用架构之MVP---&gt;天气实例

    我们知道.Android App 本质上抽象成两个层次:视图和数据.为了App在发展过程中高速的适应变化,方便维护和高速迭代,我们要将数据和视图解耦,而在解藕方面我们的前辈们在漫长的软件开发经验中为我 ...

  4. Java NIO —— Buffer(缓冲区)

    Buffer是一个抽象类,位于java.nio包中,主要用作缓冲区.注意:Buffer是非线程安全类. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO Buffer ...

  5. java Collection-Map 之 TreeMap

    TreeMap 内部定义了一个类  static final class Entry<K,V> implements Map.Entry<K,V>,(自平衡红黑二叉树)作为数据 ...

  6. Android异步处理三:Handler+Looper+MessageQueue深入详解

    在<Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面>中,我们讲到使用Thread+Handler的方式来实现界面的更新,其实是在非UI线程发送消息到U ...

  7. poj2816

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 29799   Accepted: 12090 De ...

  8. 爬虫入门【1】urllib.request库用法简介

    urlopen方法 打开指定的URL urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, ca ...

  9. This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its 错误解决办法

    This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary log ...

  10. SELinux状态修改

    查看SELinux状态: 1./usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态 SELinux status:         ...