zoukankan      html  css  js  c++  java
  • [HDU 1199] Color the Ball

    Color the Ball

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

    Total Submission(s): 4529    Accepted Submission(s): 1114 

    Problem Description
    There are infinite balls in a line (numbered 1 2 3 ....), and initially all of them are paint black. Now Jim use a brush paint the balls, every time give two integers a b and follow by a char 'w' or 'b', 'w' denotes the ball from a to b are painted white, 'b' denotes that be painted black. You are ask to find the longest white ball sequence.
     
    Input
    First line is an integer N (<=2000), the times Jim paint, next N line contain a b c, c can be 'w' and 'b'.
    There are multiple cases, process to the end of file.
     
    Output
    Two integers the left end of the longest white ball sequence and the right end of longest white ball sequence (If more than one output the small number one). All the input are less than 2^31-1. If no such sequence exists, output "Oh, my god".
     
    Sample Input
    3 1 4 w 8 11 w 3 5 b
     
    Sample Output
    8 11

    一样的题目:ZOJ 2301[数据较强]
    受不了恶心的离散化、、、、、

    查询是一次查询、暴力就是了

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    #define N 20010
    
    struct line
    {
        int l,r,c;
    }p[N];
    
    int tot;
    int x[N];
    int vis[N];
    int lazy[N<<2];
    
    void pushdown(int rt)
    {
        if(lazy[rt]!=-1)
        {
            lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
            lazy[rt]=-1;
        }
    }
    void build(int l,int r,int rt)
    {
        lazy[rt]=-1;
        if(l==r) return;
        int m=(l+r)>>1;
        build(l,m,rt<<1);
        build(m+1,r,rt<<1|1);
    }
    void update(int l,int r,int rt,int L,int R,int c)
    {
        if(l==L && R==r)
        {
            lazy[rt]=c;
            return;
        }
        pushdown(rt);
        int m=(l+r)>>1;
        if(R<=m) update(l,m,rt<<1,L,R,c);
        else if(L>m) update(m+1,r,rt<<1|1,L,R,c);
        else
        {
            update(l,m,rt<<1,L,m,c);
            update(m+1,r,rt<<1|1,m+1,R,c);
        }
    }
    void query(int l,int r,int rt)
    {
        if(lazy[rt]==1)
        {
            for(int i=l;i<=r;i++)
                vis[i]=1;
            return;
        }
        if(l>=r) return;
        pushdown(rt);
        int m=(l+r)>>1;
        query(l,m,rt<<1);
        query(m+1,r,rt<<1|1);
    }
    int main()
    {
        int i,j,n;
        while(scanf("%d",&n)!=EOF)
        {
            if(!n)
            {
                cout<<"Oh, my god
    ";
                continue;
            }
            tot=0;
            memset(vis,0,sizeof(vis));
            for(i=0;i<n;i++)
            {
                char ch;
                scanf("%d%d %c",&p[i].l,&p[i].r,&ch);
                if(p[i].l>p[i].r) swap(p[i].l,p[i].r);
                p[i].c=ch=='b'?0:1;
                x[tot++]=p[i].l;
                x[tot++]=p[i].r;
            }
    
            /* 离散化 */
            sort(x,x+tot);
            tot=unique(x,x+tot)-x;
            for(i=tot-1;i>=0;i--)
            {
                if(x[i]-x[i-1]>1) x[tot++]=x[i-1]+1;
                if(x[i]-x[i-1]>2) x[tot++]=x[i]-1;
            }
            sort(x,x+tot);
            build(0,tot-1,1);
            for(i=0;i<n;i++)
            {
                int l=lower_bound(x,x+tot,p[i].l)-x;
                int r=lower_bound(x,x+tot,p[i].r)-x;
                update(0,tot-1,1,l,r,p[i].c);
            }
            query(0,tot-1,1);
            int ans=-1,s=-1,e=-1;
            for(i=0;i<tot;i++)
            {
                if(vis[i])
                {
                    j=i;
                    while(vis[j+1]) j++;
                    if(x[j]-x[i]+1>ans)
                    {
                        ans=x[j]-x[i]+1;
                        s=x[i];
                        e=x[j];
                    }
                }
            }
            if(s!=-1)
                cout<<s<<' '<<e<<endl;
            else
                cout<<"Oh, my god
    ";
        }
        return 0;
    }
    趁着还有梦想、将AC进行到底~~~by 452181625
  • 相关阅读:
    超级变态之access查询
    计算机安全病毒问题汇集(转自华军)
    Avast I Love You
    Windows2003 3389端口修改
    希捷 250G 7200.10 8M(串口/5年盒)(买硬盘了~~~)
    DataTable 中Remove方法的使用
    我的主板(p5pl2e)
    冼东妹(为奥运冠军名字作诗)
    李彦宏告诫年轻人:向前看两年
    郭文珺(为奥运冠军名字作诗)
  • 原文地址:https://www.cnblogs.com/hate13/p/4186483.html
Copyright © 2011-2022 走看看