参考:

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=+;
struct rec
{
int a,b;
bool operator < (const rec& x) const
{
return a<x.a;
}
}; rec cow[MAXN],sunscreen[MAXN];
int C,L,ans=; int main()
{
scanf("%d%d",&C,&L);
for (int i=;i<C;i++) scanf("%d%d",&cow[i].a,&cow[i].b); //a:min b:max
for (int i=;i<L;i++) scanf("%d%d",&sunscreen[i].a,&sunscreen[i].b);//a:effect b:num
priority_queue< int,vector<int>,greater<int> > pque;
sort(cow,cow+C);
sort(sunscreen,sunscreen+L);
int j=;
for (int i=;i<L;i++)
{
while (j<C && cow[j].a<=sunscreen[i].a)
{
pque.push(cow[j].b);
j++;
}
while (!pque.empty() && sunscreen[i].b)//莫忘队列为空时也不执行
{
int temp=pque.top();
pque.pop();
if (temp<sunscreen[i].a) continue;
sunscreen[i].b--;
ans++;
}
}
cout<<ans<<endl;
return ;
}

【优先队列】POJ3614-Sunscreen的更多相关文章

  1. POJ3614 Sunscreen 优先队列+贪心

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

  2. poj3614 Sunscreen(贪心+STL)

    https://vjudge.net/problem/POJ-3614 如果这不是优先队列专题里的,我可能不一定能想到这么做. 结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉. ...

  3. POJ--3614 Sunscreen(贪心)

    题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...

  4. poj3614 Sunscreen【贪心】

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11772   Accepted: 4143 Descri ...

  5. poj3614 Sunscreen

    贪心题. 如何找出正确的贪心策略呢? 我一开始是以为按照l排序,然后从1到n遍历,挑最大的满足的防晒霜.后来发现不行.挑最小的也不行. 看了题解发现是从n到1遍历. 为什么? 因为i-1的l比i的l承 ...

  6. [POJ3614]Sunscreen (贪心)

    题意 (依然来自洛谷) 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常 ...

  7. POJ3614 Sunscreen 贪心入门

    题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...

  8. 【POJ3614 Sunscreen】【贪心】

    题面: 有c头牛,需要的亮度在[min_ci,max_ci]中,有n种药,每种m瓶,可以使亮度变为v 问最多能满足多少头牛 算法 我们自然考虑贪心,我们首先对每头牛的min进行排序,然后对于每种药,将 ...

  9. 【POJ - 3614】Sunscreen (优先队列)

    Sunscreen Descriptions C (1 ≤ C ≤ 2500) 头奶牛在海滩边晒太阳,要避免在日光浴时产生难看的灼伤,每头奶牛必须用防晒霜覆盖它的皮肤.第 i 头奶牛有一个最小和最大  ...

  10. 优先队列:POJ No 3614 Sunscreen 贪心

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6410   Accepted: 2239 Descrip ...

随机推荐

  1. 8.0docker的客户端和守护进程

    C/S 链接的方式 unix:///var/run/docker.sock 默认的 tcp://host:port fd://socketfd 在linux上进行socket 模拟 nc -U /va ...

  2. Bit banging

    Bit banging Bit banging is a technique for serial communications using software instead of dedicated ...

  3. HDU 6115 Factory LCA,暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6115 题意:中文题面 分析:直接维护LCA,然后暴力枚举集合维护答案即可. #include < ...

  4. VI编辑,backspace无法删除解决方法

    系统ubuntu 1,sudo apt-get install vim  安装vim 2, sudo vi  /etc/vim/vimrc.tiny 修改 set compatible为set noc ...

  5. CSS3新属性解释及用法

    一. transition(a标签hover渐隐效果) a:hover{transition: color 0.15s linear 0s, background-color 0.3s linear ...

  6. LeetCode Binary Tree PostorderTranversal

    Problem Description Given a binary tree, return the postorder traversal of its nodes' values. For ex ...

  7. Windows7 + OSG3.6 + VS2017 + Qt5.11

    一.准备工作 下载需要的材料: 1. OSG稳定版源代码, 3.6.3版本 2. 第三方库,选择VS2017对应的版本  https://download.osgvisual.org/3rdParty ...

  8. 不断学习UI框架的写法

    在web开发的过程中,我们会需要用到很多大大小小的插件,比如文本框,下拉树,下拉框等等各种各样的都需要.或许在开发的网页中会用到同一种插件来满足各种各样复杂的业务逻辑,比如简单的一个下拉树,有的地方需 ...

  9. 关于Logstash中grok插件的正则表达式例子

    一.前言 近期需要对Nginx产生的日志进行采集,问了下度娘,业内最著名的解决方案非ELK(Elasticsearch, Logstash, Kibana)莫属. Logstash负责采集日志,Ela ...

  10. ELK系列--justniffer0.5.12安装报错解决方法

    现象: justniffer的0.5.12(安装后显示0.5.13版本)安装过程中需要升级boost至1.46以上版本,同时在make时会出现如下报错: /opt/Python-2.6.6/Pytho ...