【优先队列】POJ3614-Sunscreen
参考:❀
#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的更多相关文章
- POJ3614 Sunscreen 优先队列+贪心
Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...
- poj3614 Sunscreen(贪心+STL)
https://vjudge.net/problem/POJ-3614 如果这不是优先队列专题里的,我可能不一定能想到这么做. 结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉. ...
- POJ--3614 Sunscreen(贪心)
题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...
- poj3614 Sunscreen【贪心】
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11772 Accepted: 4143 Descri ...
- poj3614 Sunscreen
贪心题. 如何找出正确的贪心策略呢? 我一开始是以为按照l排序,然后从1到n遍历,挑最大的满足的防晒霜.后来发现不行.挑最小的也不行. 看了题解发现是从n到1遍历. 为什么? 因为i-1的l比i的l承 ...
- [POJ3614]Sunscreen (贪心)
题意 (依然来自洛谷) 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常 ...
- POJ3614 Sunscreen 贪心入门
题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...
- 【POJ3614 Sunscreen】【贪心】
题面: 有c头牛,需要的亮度在[min_ci,max_ci]中,有n种药,每种m瓶,可以使亮度变为v 问最多能满足多少头牛 算法 我们自然考虑贪心,我们首先对每头牛的min进行排序,然后对于每种药,将 ...
- 【POJ - 3614】Sunscreen (优先队列)
Sunscreen Descriptions C (1 ≤ C ≤ 2500) 头奶牛在海滩边晒太阳,要避免在日光浴时产生难看的灼伤,每头奶牛必须用防晒霜覆盖它的皮肤.第 i 头奶牛有一个最小和最大 ...
- 优先队列:POJ No 3614 Sunscreen 贪心
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6410 Accepted: 2239 Descrip ...
随机推荐
- Webview 中FaultyInfo代码说明
class FaultyInfoHandler(tornado.web.RequestHandler): def get(self): import xmlrpc.client s = xmlrpc. ...
- 关于this问题
对于关键字this,其实很好理解,谁调用我就指向谁.下面举个例子说明: 其实这也是在学习闭包中的一个案例: var name = "The window"; var obj = { ...
- perl HTML::LinkExtor模块(2)
use LWP::Simple; use HTML::LinkExtor; $html_code = get("https://tieba.baidu.com/p/4929234512&qu ...
- deepin安装metasploit
[1]安装metasploit 1.curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/tem ...
- arping详解
arping干嘛用的? arping主要干的活就是查看ip的MAC地址及IP占用的问题. 参数 -0:指定源地址为0.0.0.0,这个一般是在我们刚刚安装好系统,电脑还没配置好IP的时候 -a:Aud ...
- linux===linux后台运行和关闭、查看后台任务(转)
fg.bg.jobs.&.ctrl + z都是跟系统任务有关的,虽然现在基本上不怎么需要用到这些命令,但学会了也是很实用的 一.& 最经常被用到这个用在一个命令的最后,可以把这个命令放 ...
- 再议perl写多线程端口扫描器
再议perl写多线程端口扫描器 http://blog.csdn.net/sx1989827/article/details/4642179 perl写端口多线程扫描器 http://blog.csd ...
- 网站服务器压力Web性能测试(2):Webbench:最多模拟3万个并发连接数测试压力
1.Webbench最多可以模拟3万个并发连接数来测试服务器压力,可以设置压力测试时间和测试请求的成功率.安装Webbench命令: wget https://home.tiscali.cz/~cz2 ...
- gunicorn 启动无日志
gunicorn -c gunicorn_info.py info:app 接手整理老项目,发现有个服务迁移后启动不了,也没报错信息 修改gunicorn_info.py里的daemon = not ...
- centos 6 编译安装php-5.4/5.5(lamp模式)
在安装LAMP架构时,我们常用php-5.3的版本 现进行php-5.4/5.5的编译安装演示: [root@localhost ~]# cd /usr/local/src [root@localho ...