https://vjudge.net/problem/POJ-3614

如果这不是优先队列专题里的,我可能不一定能想到这么做。

结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉。

贪心策略:先对牛按from升序,对瓶子按w升序,优先队列是按to的小顶堆;

    然后枚举瓶子,只要当前牛的from<=当前瓶子的w就入队,直到不满足为止;

    然后在队伍里取出一个,判断它的是否to>=w以及cover数是否还够用。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
int n, m;
struct Node{
int from, to;
int w;
friend bool operator<(const Node a, const Node b){
return a.to>b.to;//小顶堆按to排
}
}node[];
struct Edge{
int w, cover;
}edge[];
bool cmp(const Edge a, const Edge b)
{
return a.w<b.w;
}
bool cmp2(const Node a, const Node b)
{
return a.from<b.from;
}
int main()
{
priority_queue<Node> q;
cin >> n >> m;
for(int i = ; i < n; i++){
cin >> node[i].from >> node[i].to;
}
for(int i = ; i < m; i++){
cin >> edge[i].w >> edge[i].cover;
}
sort(edge, edge+m, cmp);
sort(node, node+n, cmp2);//一开始没加这个wa了好久
int k = , ans=;
for(int i = ; i < m; i++){//瓶子
while(k < n&&node[k].from<=edge[i].w){//左边界在它的前面就入队
q.push(node[k]);
k++;
}
while(!q.empty()){
Node t = q.top(), p;
q.pop();
if(t.to>=edge[i].w&&edge[i].cover>){//两种都满足可以ans++
edge[i].cover--;
ans++;
}
if(edge[i].cover == ) break; }
}
cout << ans << endl;
return ;
}

poj3614 Sunscreen(贪心+STL)的更多相关文章

  1. [POJ3614]Sunscreen (贪心)

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

  2. POJ3614 Sunscreen 贪心入门

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

  3. POJ--3614 Sunscreen(贪心)

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

  4. POJ3614 Sunscreen 优先队列+贪心

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

  5. poj3614 Sunscreen【贪心】

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

  6. 【POJ3614 Sunscreen】【贪心】

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

  7. POJ 3614 Sunscreen 贪心

    题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...

  8. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

  9. POJ 3614:Sunscreen 贪心+优先队列

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5378   Accepted: 1864 Descrip ...

随机推荐

  1. alpha冲刺4/10

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺4 团队部分 后敬甲 过去两天完成了哪些任务 文字描述 主页部分图标的替换 -拍照按钮的设计和测试 GitHub代码 ...

  2. csv导入数据到mongodb3.2

    mongoimport.exe -d paper -c paper K:\paper.csv --type csv -f id,name 数据库名 表名      文件所在位置      文件类型   ...

  3. python__int 部分内部功能介绍

    查看创建的对象的类型: age=18 print(type(age)) 结果: <class 'int'> x.bit_length():返回二进制的位数 Python中进制的转换: Py ...

  4. 删除Docker中所有已停止的容器

    方法一: #显示所有的容器,过滤出Exited状态的容器,取出这些容器的ID, sudo docker ps -a|grep Exited|awk '{print $1}' #查询所有的容器,过滤出E ...

  5. Linux下C语言的进程控制编程

    代码: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/ty ...

  6. 修改tp5的默认配置文件的位置

    web |--application | |--admin | |--home | | |--controller | | |--model | | |--view | | |--extra 5.01 ...

  7. Spring BPP中优雅的创建动态代理Bean

    一.前言 本文章所讲并没有基于Aspectj,而是直接通过Cglib以及ProxyFactoryBean去创建代理Bean.通过下面的例子,可以看出Cglib方式创建的代理Bean和ProxyFact ...

  8. 分布式缓存技术redis系列(二)——详细讲解redis数据结构(内存模型)以及常用命令

    https://www.cnblogs.com/hjwublog/p/5639990.html

  9. 进程篇:wait & waitpid

    #include <sys/types.h> /* 提供类型pid_t的定义 */ #include <sys/wait.h> pid_t wait(int *status) ...

  10. DataGrid绑定DataTable出错

    直接用DataGrid.ItemSource = DataTable.DefaultView时会出现以下错误: target element is 'TextBlock' (Name=''); tar ...