首页 > 其他 > 详细

bzoj1651[Usaco2006 Feb]Stall Reservations 专用牛棚*

时间:2016-09-19 22:10:00      阅读:134      评论:0      收藏:0      [点我收藏+]

bzoj1651[Usaco2006 Feb]Stall Reservations 专用牛棚

题意:

有N头牛,每头牛有个喝水时间段,这段时间它将专用一个棚。现在给出每头牛的喝水时间段,问至少要多少个棚才能满足它们的要求。n≤50000,时刻≤1000000。

题解:

时间段左端点对应的sum元素++,右端点+1对应的sum元素--,最后从左到右加一遍就可以得到每个时刻的喝水牛数,找个最大值就可以了。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <queue>
 5 #define inc(i,j,k) for(int i=j;i<=k;i++)
 6 #define maxn 1000010
 7 using namespace std;
 8 
 9 inline int read(){
10     char ch=getchar(); int f=1,x=0;
11     while(ch<0||ch>9){if(ch==-)f=-1; ch=getchar();}
12     while(ch>=0&&ch<=9)x=x*10+ch-0,ch=getchar();
13     return f*x;
14 }
15 int sm[maxn],n,mx,ans;
16 int main(){
17     n=read(); inc(i,1,n){int x=read(),y=read(); sm[x]++; sm[y+1]--; mx=max(mx,y);}
18     inc(i,1,mx)sm[i]+=sm[i-1]; inc(i,1,mx)ans=max(ans,sm[i]); printf("%d",ans); return 0;
19     return 0;
20 }

 

20160919

bzoj1651[Usaco2006 Feb]Stall Reservations 专用牛棚*

原文:http://www.cnblogs.com/YuanZiming/p/5886779.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!