BZOJ1651Stall Reservations 专用牛棚

1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 698 Solved: 391
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
5
1 10
2 4
3 6
5 8
4 7
Sample Output
4
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
Source
Silver
线段树裸题。。
可以发现一个神奇的规律。。
覆盖次数最多的点就是答案。。
于是区间修改+区间查询最大值水过。。
还有就是查询区间是1-1000000
附上本蒟蒻的代码:

#include<cstdio>
#include<climits>
#include<iostream>
using namespace std;
int n,a[50001],delta[4000001];
struct kx
{
    int value;
}node[4000001];

int read()
{
    int w=0,c=1; char ch=getchar();
    while (ch<'0' || ch>'9')
      {
        if (ch=='-') c=-1;
        ch=getchar();
      }
    while (ch>='0' && ch<='9')
      w=w*10+ch-'0',ch=getchar();
    return w*c;
}

void update(int s)
{
    node[s].value=max(node[s*2].value,node[s*2+1].value);
}

void paint(int s,int z,int l,int r)
{
    node[s].value+=z,delta[s]+=z;
}

void pushdown(int s,int l,int r)
{
    int mid=(l+r)/2;
    paint(s*2,delta[s],l,mid),paint(s*2+1,delta[s],mid+1,r),delta[s]=0;
}

void insert(int s,int l,int r,int x,int y,int z)
{
    int mid=(l+r)/2;
    if (x<=l && y>=r)
      {
        paint(s,z,l,r);
        return;
      }
    pushdown(s,l,r);
    if (x<=mid) insert(s*2,l,mid,x,y,z);
    if (y>mid) insert(s*2+1,mid+1,r,x,y,z);
    update(s);
}

int query(int s,int l,int r,int x,int y)
{
    int mid=(l+r)/2,ans;
    if (x<=l && y>=r) return node[s].value;
    pushdown(s,l,r);
    if (x<=mid) ans=query(s*2,l,mid,x,y);
    else ans=-INT_MAX;
    if (y>mid) ans=max(ans,query(s*2+1,mid+1,r,x,y));
    update(s);
    return ans;
}

int main()
{
    int i,x,y;
    n=read();
    for (i=1;i<=n;i++)
      {
        x=read(),y=read();
        insert(1,1,1000000,x,y,1);
      }
    printf("%d\n",query(1,1,1000000,1,1000000));
    return 0;
}

AC100纪念。。
都流传着AC100表白的人生成就。。
然而我早就体验过三次。。
什么??你说表白多了有经验??
我觉得我还不如安安静静地当个0级小怪物。。
离省选、APIO、CTSC不远了。。
然而还是没有什么动力。。
无论是OI还是文化课。。
尽管在学校里有kxj。。
不知道这样的状态会持续多久。。
做一道题总是安静不下来。。
不能认真地去思考。。
在学校里不管是文理科上课都很懒散。。
晚上在宿舍里就颓废。。
这不是个好征兆。。
现在仅仅是高一。。还有机会挽救。。
其实还是比较希望kxj能看到这篇。。
毕竟Ta目前是我比较大的动力。。
尽管说着别想多。。其实自己已经想多。。
其实你的心意我都懂。。
走一步看一步吧。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值