BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
题目
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 553 Solved: 307
[Submit][Status]
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
题解
这道题用时间戳的思路就可以了,我们统计同一时间最大的时间戳个数就是答案。
代码
/*Author:WNJXYK*/
#include<cstdio>
using namespace std; #define LL long long
#define Inf 2147483647
#define InfL 10000000000LL inline int abs(int x){if (x<) return -x;return x;}
inline int abs(LL x){if (x<) return -x;return x;}
inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
inline int remin(int a,int b){if (a<b) return a;return b;}
inline int remax(int a,int b){if (a>b) return a;return b;}
inline LL remin(LL a,LL b){if (a<b) return a;return b;}
inline LL remax(LL a,LL b){if (a>b) return a;return b;}
inline void read(int &x){x=;int f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}x=x*f;}
inline void read(LL &x){x=;LL f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}x=x*f;}
inline void read(int &x,int &y){read(x);read(y);}
inline void read(LL &x,LL &y){read(x);read(y);}
inline void read(int &x,int &y,int &z){read(x,y);read(z);}
inline void read(int &x,int &y,int &n,int &m){read(x,y);read(n,m);}
inline void read(LL &x,LL &y,LL &z){read(x,y);read(z);}
inline void read(LL &x,LL &y,LL &n,LL &m){read(x,y);read(n,m);}
const int Maxn=;
int n;
int a,b;
int t[Maxn+];
int main(){
read(n);
for (;n--;){
read(a,b);
t[a]++;
t[b+]--;
}
int Ans=;
for (int i=;i<=Maxn;i++){
t[i]=t[i-]+t[i];
Ans=remax(Ans,t[i]);
}
printf("%d\n",Ans);
return ;
}
BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚的更多相关文章
- BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚( 线段树 )
线段树.. -------------------------------------------------------------------------------------- #includ ...
- BZOJ 1651 [Usaco2006 Feb]Stall Reservations 专用牛棚:优先队列【线段最大重叠层数】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1651 题意: 给你n个线段[a,b],问你这些线段重叠最多的地方有几层. 题解: 先将线段 ...
- bzoj 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚【贪心+堆||差分】
这个题方法还挺多的,不过洛谷上要输出方案所以用堆最方便 先按起始时间从小到大排序. 我用的是greater重定义优先队列(小根堆).用pair存牛棚用完时间(first)和牛棚编号(second),每 ...
- 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 566 Sol ...
- 【BZOJ】1651: [Usaco2006 Feb]Stall Reservations 专用牛棚(线段树/前缀和 + 差分)
http://www.lydsy.com/JudgeOnline/problem.php?id=1651 很奇妙.. 我们发现,每一时刻的重叠数选最大的就是答案.... orz 那么我们可以线段树维护 ...
- BZOJ1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 509 Sol ...
- BZOJ 1652: [Usaco2006 Feb]Treats for the Cows( dp )
dp( L , R ) = max( dp( L + 1 , R ) + V_L * ( n - R + L ) , dp( L , R - 1 ) + V_R * ( n - R + L ) ) 边 ...
- BZOJ 1652: [Usaco2006 Feb]Treats for the Cows
题目 1652: [Usaco2006 Feb]Treats for the Cows Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 234 Solve ...
- BZOJ 1653 [Usaco2006 Feb]Backward Digit Sums ——搜索
[题目分析] 劳逸结合好了. 杨辉三角+暴搜. [代码] #include <cstdio> #include <cstring> #include <cmath> ...
随机推荐
- Linux(Debain)环境安装WordPress
一.相关组件安装 1. 安装Apache apt-get install apache2 安装完毕后浏览器 http://localhost/ 或者 http://127.0.0.1 出现It Wor ...
- 五毛的cocos2d-x学习笔记06-处理用户交互
前几篇感觉自己在写教育文章,╮(╯▽╰)╭.今天换成开发者的口吻,毕竟我也是在边学边写博客. 处理用户交互包括:单点触摸.多点触摸.事件传递.传感器.物理按键等部分. 单点触摸: 触摸事件传递顺序 o ...
- ubuntu下使用codeblocks
集成开发环境搭建 1. 安装build-essential 方法: sudo apt-get install build-essential 作用:提供编译程序必须软件包的列表信息,编译程序有了这个软 ...
- BZOJ 2733: [HNOI2012]永无乡(treap + 启发式合并 + 并查集)
不难...treap + 启发式合并 + 并查集 搞搞就行了 --------------------------------------------------------------------- ...
- Centos rpm缺少依赖无法安装mysql5.5
rpm -ivh mysql-5.5.22-2.1.i386.rpm --nodeps --force 缺少依赖导致rpm -ivh mysql-5.5.22-2.1.i386.rpm命令无法安装!
- Linux下 保存 git账号密码
一.通过文件方式 1.在~/下, touch创建文件 .git-credentials, 用vim编辑此文件,输入内容格式: touch .git-credentials vim .git-crede ...
- 【转】使用Boost Graph library(二)
原文转自:http://shanzhizi.blog.51cto.com/5066308/942972 让我们从一个新的图的开始,定义一些属性,然后加入一些带属性的顶点和边.我们将给出所有的代码,这样 ...
- 通往WinDbg的捷径
通往WinDbg的捷径(一) 原文:http://www.debuginfo.com/articles/easywindbg.html译者:arhat时间:2006年4月13日关键词:CDB WinD ...
- 【蓝桥杯】入门训练 Fibonacci数列
入门训练 Fibonacci数列 时间限制:1.0s 内存限制:256.0MB 问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. ...
- 犯罪团伙利用POS机刷信用卡积分转卖 年获利千万
今年1月20日,广东省公安厅展示去年缴获的盗刷专用POS机. 今年1月20日,广东省公安厅展示了一批缴获的盗刷信用卡工具. 他们是一群靠信用卡谋生的年轻人,平均年龄不超过30岁. 他们将各银行信用 ...