poj3614 Sunscreen(贪心+STL)
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)的更多相关文章
- [POJ3614]Sunscreen (贪心)
题意 (依然来自洛谷) 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常 ...
- POJ3614 Sunscreen 贪心入门
题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...
- POJ--3614 Sunscreen(贪心)
题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...
- POJ3614 Sunscreen 优先队列+贪心
Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...
- poj3614 Sunscreen【贪心】
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11772 Accepted: 4143 Descri ...
- 【POJ3614 Sunscreen】【贪心】
题面: 有c头牛,需要的亮度在[min_ci,max_ci]中,有n种药,每种m瓶,可以使亮度变为v 问最多能满足多少头牛 算法 我们自然考虑贪心,我们首先对每头牛的min进行排序,然后对于每种药,将 ...
- POJ 3614 Sunscreen 贪心
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...
- Codeforces Round #595 (Div. 3)D1D2 贪心 STL
一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...
- POJ 3614:Sunscreen 贪心+优先队列
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5378 Accepted: 1864 Descrip ...
随机推荐
- vector的 []
摘自<C++编程剖析> #include <iostream> #include <vector> using namespace std; int main() ...
- Lambda表达式树解析(下)
概述 前面章节,总结了Lambda树的构建,那么怎么解析Lambda表达式树那?Lambda表达式是一种委托构造而成,如果能够清晰的解析Lambda表达式树,那么就能够理解Lambda表达式要传递的正 ...
- Python_序列化和反序列化模块
序列化:将对象转换为可通过网络传输或可存储到本地磁盘的数据格式的转换过程,称为序列化,反之,称为反序列化 json: 用来实现不同语言,不同程序直接的信息交互,json支持所有高级语言之间的序列化交互 ...
- Python学习(十六)—— 数据库
一.数据库介绍 数据库(Database,DB)是按照数据结构来组织.存储和管理数据的,并且是建立在计算机存储设备上的仓库. 数据库指的是以一定方式存储在一起.能为多个用户共享.具有尽可能小的冗余度. ...
- BZOJ1823 [JSOI2010]满汉全席 2-sat
原文链接http://www.cnblogs.com/zhouzhendong/p/8125944.html 题目传送门 - BZOJ1823 题意概括 有n道菜,分别可以做成满式和汉式(每道菜只能做 ...
- .net core cookie登录和session的 DataProtectionProvider 加入 redis
string redisConnectionString = Configuration.GetSection("Storage:Redis").GetValue<strin ...
- python中@staticmethod、@classmethod和实例方法
1.形式上的异同点: 在形式上,Python中:实例方法必须有self,类方法用@classmethod装饰必须有cls,静态方法用@staticmethod装饰不必加cls或self,如下代码所示: ...
- Validation failed for object='employee'. Error count: 1问题解决
2018-11-13 在表单提交时有时候会提示 Validation failed for object=’user’. Error count: 1,其中user是表的名字,Error count是 ...
- CentOS7配置FTP服务器增强版~(零基础学会FTP配置)
ps:原文不知出处,但是原文也不能正常启动,这里做了一些修改!如果能正常配置请在下方留言让更多的人看到,因为之前我本人照着网上的教程安装卸载了十多次也无法正常使用,不希望后面的兄弟继续浪费时间,如果不 ...
- 解决Ubuntu中Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another proce...
解决Ubuntu中Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another proce... ...