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

cin和scanf差这么多么。。tle和300ms

思路:先对结构体x升序y升序,再对优先队列重载<,按y升序。

  然后依次入队,如果node[i].x<=q.top().y ans++, 否则出队,入队,使用出队的那个摊位。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
struct Node{
int x, y;
int id;
bool operator<(const Node &a)const{
return y > a.y;
}
}node[];
int n, maxm = -INF, b[];
bool cmp(const Node a, const Node b)
{
if(a.x != b.x)
return a.x<b.x;
return a.y<b.y;
}
int main()
{
scanf("%d", &n);
int ans = ;
for(int i = ; i < n; i++){
scanf("%d%d", &node[i].x, &node[i].y);
node[i].id=i+;
}
sort(node, node+n, cmp);
priority_queue<Node> q;
q.push(node[]);
b[node[].id] = ans;
for(int i = ; i < n; i++){
Node t = q.top();
if(node[i].x <= t.y){
q.push(node[i]);
ans++;
b[node[i].id] = ans;
//maxm = max(maxm, ans);
}
else if(node[i].x > t.y){
q.pop();
q.push(node[i]);
b[node[i].id] = b[t.id];
//cout << b[t.id] << "t";
}
}
printf("%d\n", ans);
for(int i = ; i <= n; i++){
printf("%d\n", b[i]);
} return ;
}

poj3190 Stall Reservations(贪心+STL)的更多相关文章

  1. poj3190 Stall Reservations (贪心+优先队列)

    Cleaning Shifts Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

  2. POJ3190 Stall Reservations 贪心

    这是个典型的线程服务区间模型.一些程序要在一段时间区间上使用一段线程运行,问至少要使用多少线程来为这些程序服务? 把所有程序以左端点为第一关键字,右端点为第二关键字从小到大排序.从左向右扫描.处理当前 ...

  3. POJ 3190 Stall Reservations贪心

    POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...

  4. [USACO06FEB] Stall Reservations 贪心

    [USACO06FEB] Stall Reservations 贪心 \(n\)头牛,每头牛占用时间区间\([l_i,r_i]\),一个牛棚每个时间点只能被一头牛占用,问最少新建多少个牛棚,并且每头牛 ...

  5. POJ--3190 Stall Reservations(贪心排序)

    这里 3190 Stall Reservations 按照吃草时间排序 之后我们用 优先队列维护一个结束时间 每次比较堆顶 看是否满足 满足更新后放到里面不满足就在后面添加 #include<c ...

  6. POJ3190 Stall Reservations 【贪婪】

    Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3106   Accepted: 111 ...

  7. POJ - 3190 Stall Reservations 贪心+自定义优先级的优先队列(求含不重叠子序列的多个序列最小值问题)

    Stall Reservations Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one w ...

  8. poj 3190 Stall Reservations 贪心 + 优先队列

    题意:给定N头奶牛,每头牛有固定的时间[a,b]让农夫去挤牛奶,农夫也只能在对应区间对指定奶牛进行挤奶, 求最少要多少个奶牛棚,使得在每个棚内的奶牛的挤奶时间不冲突. 思路:1.第一个想法就是贪心,对 ...

  9. poj3190 Stall Reservations

    我一开始想用线段树,但是发现还要记录每头cow所在的棚...... 无奈之下选择正解:贪心. 用priority_queue来维护所有牛棚中结束时间最早的那个牛棚,即可得出答案. 注意代码实现的细节. ...

随机推荐

  1. 自定义rem

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. bzoj4059

    题解: 还是一道不错的题目 首先它要求每个区间都满足要求,所以我们很容易想到将它映射到二维平面上 然后我们算出每个数的前驱以及后继li,ri 那么第一维是li-i,第二维是i-ri的区间就是合法的,同 ...

  3. 带你了解zabbix如何监控mysql主从到报警触发

    本章博客我们一起来聊一聊如何监控mysql数据库主从状态? 思路梳理: 1)首先我们都知道,判断Mysql主从是否正常,是通过主从上面的SQL和IO线程都为yes状态判断(通过awk取值,grep过滤 ...

  4. springboot创建错误

    1.Unknown system variable 'query_cache_size' 解决:https://www.cnblogs.com/nicknailo/articles/9074804.h ...

  5. 解决 jQuery 实现父窗口的问题 如window.parent.document.getElementById().innerHTML

    因为先前遇到的问题,所以我考虑采用 IFRAME 来隔离不同的脚本,从而实现我需要的效果. 在框架中,我用 JavaScript 获取 JSON 数据,组织成 HTML 代码,最后将其填充至上层文档的 ...

  6. nginx+keepalived实现 负载均衡 高可用

    Vip: 192.168.220.18 Rip1:192.168.220.2 Rip:192.168.220.3 Rip可以配置在一个服务器上通过ip做虚拟主机 1 rs上配置环境 2 配置应用 Yu ...

  7. Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)

    Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...

  8. 分布式配置 Spark 2.0版本 2.1版本 1.6版本

    apache的各个软件各个版本下载:  http://archive.apache.org/dist/ 1.下载spark. sudo tar -zxf ~/下载/spark-2.0.2-bin-wi ...

  9. LCA算法解析-Tarjan&倍增&RMQ

    原文链接http://www.cnblogs.com/zhouzhendong/p/7256007.html UPD(2018-5-13) : 细节修改以及使用了Latex代码,公式更加美观.改的过程 ...

  10. Python编译安装遇到的问题

    1.python在make时候报错 Python build finished, but the necessary bits to build these modules were not foun ...