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): 5010    Accepted Submission(s): 1243


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
 

Author
ZHOU, Kai
 

Source
ZOJ Monthly, February 2005

写的时候错误百出啊,,

//hdu 1199
#include<map>
#include<vector>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#define inf 0x3f3f3f3f
#define mem(a,x) memset(a,x,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

inline int in()
{
    int res=0;char c;
    while((c=getchar())<'0' || c>'9');
    while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
    return res;
}
struct st
{
    int l;int r;

}a[22222]; //要大一点,因为有很多会分成两个的

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int k=0;
        for(int i=0;i<n;i++)
        {
            int l=in(),r=in();
            char c=getchar();
            if(c=='w')
            {
                a[k].l=l;
                a[k++].r=r;
            }

            if(c=='b')
            {
                int tmp=k;
                for(int j=0;j<tmp;j++)        //4种情况
                {
                    if(a[j].l>=l && a[j].r<=r)  a[j].l=-10,a[j].r=-inf;
                    else if(a[j].l<l && a[j].r>=l && a[j].r<=r ) a[j].r=l-1;
                    else if(a[j].l<=r && a[j].l>=l &&  a[j].r>r ) a[j].l=r+1;
                    else if(a[j].l<l && a[j].r>r )
                    {

                        a[k].l=r+1;
                        a[k++].r=a[j].r;
                        a[j].r=l-1;
                    }
                }
            }
            else
            {

                for(int j=0;j<k;j++)  //两种情况就行
                {
                    if(a[j].l<l && a[j].r>=l && a[j].r<=r ) l=a[j].l;   //要更新l,而不是a[j].l
                    else if(a[j].l>=l && a[j].l<=r && a[j].r>r ) r=a[j].r;//只更新a[j]的话可能造成漏掉一些后面能满足情况的
                }
                a[k-1].l=l;   //将当前的节点也更新
                a[k-1].r=r;
            }

        }

        int ans1=0,ans2=-1;
        for(int i=0;i<k;i++)
        {
            if(a[i].r-a[i].l>ans2-ans1)
            {
                ans1=a[i].l;
                ans2=a[i].r;
            }
        }
        if(ans1==0 && ans2==-1)puts("Oh, my god");
        else
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值