bzoj1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 942 Solved: 544
[Submit][Status][Discuss]
Description
Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obviously, FJ must create a reservation system to determine which stall each cow can be assigned for her milking time. Of course, no cow will share such a private moment with other cows. Help FJ by determining: * The minimum number of stalls required in the barn so that each cow can have her private milking period * An assignment of cows to these stalls over time
有N头牛,每头牛有个喝水时间,这段时间它将专用一个Stall 现在给出每头牛的喝水时间段,问至少要多少个Stall才能满足它们的要求
Input
* Line 1: A single integer, N
* Lines 2..N+1: Line i+1 describes cow i's milking interval with two space-separated integers.
Output
* Line 1: The minimum number of stalls the barn must have.
* Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.
Sample Input
1 10
2 4
3 6
5 8
4 7
Sample Output
OUTPUT DETAILS:
Here's a graphical schedule for this output:
Time 1 2 3 4 5 6 7 8 9 10
Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..
Stall 3 .. .. c3>>>>>>>>> .. .. .. ..
Stall 4 .. .. .. c5>>>>>>>>> .. .. ..
Other outputs using the same number of stalls are possible.
HINT
不妨试下这个数据,对于按结束点SORT,再GREEDY的做法 1 3 5 7 6 9 10 11 8 12 4 13 正确的输出应该是3
/* 红果果的差分题目 */ #include<iostream> #include<cstdio> #include<cstring>#define N 500001using namespace std; int a[N<<2],l,r,n,m,L,R,ans;int main() {scanf("%d",&n);L=1,R=1000000;for(int i=1;i<=n;i++){scanf("%d%d",&l,&r);a[l]++;a[r+1]--;}int tot=0;for(int i=L;i<=R;i++){tot+=a[i];ans=max(ans,tot);}printf("%d\n",ans);return 0; }
转载于:https://www.cnblogs.com/L-Memory/p/7359931.html
bzoj1651: [Usaco2006 Feb]Stall Reservations 专用牛棚相关推荐
- 51nod 1428 bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 951 So ...
- BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 876 So ...
- bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚【贪心+堆||差分】
这个题方法还挺多的,不过洛谷上要输出方案所以用堆最方便 先按起始时间从小到大排序. 我用的是greater重定义优先队列(小根堆).用pair存牛棚用完时间(first)和牛棚编号(second),每 ...
- 【贪心】Stall Reservations(luogu 2859/poj 3190)
Stall Reservations luogu 2859 poj 3190 题目大意: 有n头牛,每头牛都有自己的挤奶时间,挤奶时间内每头牛用一个奶棚,现在问最少需要多少个奶棚 输入样例 5 1 1 ...
- Stall Reservations
题目:Stall Reservations 总结:这道题按照时间的开始的从小到大排序,如果开始时间相同,那么就按照结束时间从小到大,用n2的时间复杂度,只要有后面的开始时间大于前面的结束时间,那么就是 ...
- Stall Reservations POJ
原题链接 经典贪心题目. 思路:开结构体cow.stall分别表示牛.畜栏,其中,每个cow都有编号.开始挤奶.结束挤奶时间,每个stall都有编号.当前在该畜栏中挤奶的牛的挤奶结束时间. struc ...
- 挑战程序设计竞赛 POJ Stall Reservations
题目 没想到用优先队列,我最开始的思路是对每个区间的结束时间排序,优先处理结束早的区间,但题目下面已经提示了,优先处理开始时间早的,对已经在stall里奶牛优先处理结束时间早的. #include & ...
- POJ 3190: Stall Reservations
思路: 1.读入数据,将奶牛的相关数据存在数组中,按开始时间从前到后排列 2.定义最小堆(位于根上的奶牛的结束时间最早)(用于找到已经使用结束的牛棚.若用数组存储每个牛棚的使用结束时间,再找结束时间最 ...
- POJ 3190 Stall Reservations(贪心算法)
有 n头牛(1<=n<=50,000)要挤奶.给定每头牛挤奶的时间区 间[A,B] (1<=A<=B<=1,000,000,A,B为整数). 牛需要呆畜栏里才能挤奶.一个 ...
- Stall Reservations POJ - 3190(贪心+优先队列)
题 这里有N只 (1 <= N <= 50,000) 挑剔的奶牛! 他们如此挑剔以致于必须在[A,B ]的时间内产奶(1 <= A <= B <= 1,000,000)当 ...
最新文章
- pycharm+PyQt5+python最新开发环境配置,踩坑过程详解
- spark源码解析之scala基本语法
- Ecplise中的Maven项目提示找不到jar包
- linux系统安装锐捷客户端下载,Linux在宿舍里如何上网?--Fedora下锐捷802.1x客户端软件的安装和使用方法...
- figma下载_在Figma中进行原型制作的技巧和窍门
- linux安装python3.6 setuptools_linux下安装Python3.6.1
- laravel实现前后台路由分离(转载)
- linux下pip换源——修改pip.conf文件
- bugfree 数据库配置 显示No such file or directory
- 第九集(第二部分)思科路由器IOS升级过程视频记录
- 基于AE+C#的栅格IDW插值的实现
- 暴风激活后浏览器被锁定首页
- 仿网易LOFTER视差滚动列表
- luhn算法 java_java – 使用luhn算法验证信用卡号
- 十大排序算法代码集锦(java)
- ubuntu 17\18.04 调节鼠标指针速度
- vue Tesseract的 ocr 文字识别
- 中国机械式停车设备行业投资建议与发展机遇研究报告2022版
- 你真的认为iPhone只是一部手机?苹果惊天秘密之 二
- mysql插座返回6M数据_MySQL数据库设计与应用智慧树期末答案
热门文章
- xshell远程控制(连接)两个VMware同时启动的Linux操作系统
- mysql子查询的语法,MySQL语法------13-----子查询(三)
- mssql 不能连接mysql,ASP连接MSSQL的错误:拒绝访问_MySQL
- C# Linq以及反射总结
- Unity中制作小地图
- 缺页中断——FIFO、LRU、OPT这三种置换算法
- python 自动化发送邮件_干货 | 解放双手,用Python实现自动发送邮件
- python竖着输出_Python中三种格式化输出的方式
- 【渝粤教育】国家开放大学2018年秋季 8109-22T (1)货币银行学 参考试题
- Linux 创建和销毁 urb