题意:给出n头牛必须单独占用一台机器的时间段,问至少需要多少台机器

先按照每头牛的时间的x来排序,然后用一个优先队列(优先选取最小的)维护已经喂好的牛的最小的结束时间

比如现在优先队列里面有m头牛已经完成了饲喂,

对于第m+1头牛, 如果它的开始时间小于这m头牛里面的最小的结束时间,那么必须增加一台机器,同时把第m+1头牛放进队列

如果它的开始时间大于这m头牛里面的最小的结束时间,把当前队头弹出,再把m+1头牛放进去

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; struct node{
int x,y,id;
bool operator < (const node &rsh) const {
return rsh.y < y;
}
} a[maxn]; int cmp(node n1,node n2){
return n1.x < n2.x;
} int ans[maxn]; int n; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%d %d",&a[i].x,&a[i].y);
a[i].id=i;
}
sort(a+,a+n+,cmp);
priority_queue<node> q;
q.push(a[]);
ans[a[].id]=;
int cnt=; for(int i=;i<=n;i++){
node tmp=q.top();
if(a[i].x <= tmp.y){
ans[a[i].id]=++cnt;
q.push(a[i]);
}
else{
q.pop();
q.push(a[i]);
ans[a[i].id] = ans[tmp.id];
} } printf("%d\n",cnt);
for(int i=;i <= n;i++)
printf("%d\n",ans[i]); return ;
}

POJ 3190 Stall Reservations 【贪心 优先队列】的更多相关文章

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

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

  2. POJ 3190 Stall Reservations贪心

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

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

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

  4. POJ 3190 Stall Reservations (优先队列)C++

    Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7646   Accepted: 271 ...

  5. poj 3190 Stall Reservations

    http://poj.org/problem?id=3190 Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  6. POJ 3190 Stall Reservations【贪心】

    POJ 3190 题意: 一些奶牛要在指定的时间内挤牛奶,而一个机器只能同时对一个奶牛工作.给你每头奶牛的指定时间的区间(闭区间),问你最小需要多少机器.思路:先按奶牛要求的时间起始点进行从小到大排序 ...

  7. POJ -3190 Stall Reservations (贪心+优先队列)

    http://poj.org/problem?id=3190 有n头挑剔的奶牛,只会在一个精确时间挤奶,而一头奶牛需要占用一个畜栏,并且不会和其他奶牛分享,每头奶牛都会有一个开始时间和结束时间,问至少 ...

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

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

  9. [USACO06FEB] Stall Reservations 贪心

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

随机推荐

  1. Rabbit MQ 学习 (一)Window安装Erlang环境

    之前也没有用过Rabbit MQ ,最近正在学习中,记性不好,特意记一下. 百度一下 先得 安装 Erlang 并且 设置环境变量. 在Erlang 官网去下载,那个慢呀... 还好CSDN 里有人提 ...

  2. Android开发实现QQ三方登录 标签: android开发qq三方登录

    本文分为两个部分:一是QQ的授权部分:二是获取用户的基本信息部分 一.授权部分 1.首先,先去腾讯开放平台获取APP ID和APP KEY(未注册腾讯开发者账号的可能需要先注册账号),获取的过程还是还 ...

  3. Android7.0打开sdacrd图片问题

    1.点击item,通过intent打开指定路径的图片. 2.测试6.0,5.0正常运行代码: File file=new File(item.address): Intent intent = new ...

  4. POJ 1995 Raising Modulo Numbers 【快速幂取模】

    题目链接:http://poj.org/problem?id=1995 解题思路:用整数快速幂算法算出每一个 Ai^Bi,然后依次相加取模即可. #include<stdio.h> lon ...

  5. Functional programming-函数式编程

    In computer science, functional programming is a programming paradigm—a style of building the struct ...

  6. java读取文件流和写入

    package jsoup;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStre ...

  7. zabbix部署监控端(server)以及页面优化

    实验环境准备 172.20.10.2 server.zabbix.com 172.20.10.3 agent.zabbix.com 172.20.10.8 windows10 Server 端 [ro ...

  8. 六、利用frp穿透连接内网的linx系统和windows系统

    服务端的配置 # frps.ini [common] bind_port = 7000 说明:防火墙放行该端口 启动:./frps -c ./frps.ini 后台启动:nohup ./frps -c ...

  9. 设置PATH 环境变量、pyw格式、命令行运行python程序与多重剪贴板

    pyw格式简介: 与py类似,我认为他们俩卫衣的不同就是前者运行时候不显示终端窗口,后者显示 命令行运行python程序: 在我学习python的过程中我通常使用IDLE来运行程序,这一步骤太过繁琐( ...

  10. Redis-server在windows下闪退

    在win7下使用Redis(windows版)很简单,只需要去Git上下载一个压缩包,解压运行即可.但是前段时间发现win10下双击redis-server既然闪退.非常不解... 在观察了错误日志才 ...