HDU 1199 Color the ball discrete segment tree

Source: Internet
Author: User

C-color the ballTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i6 4u Submit Status

Description

There is infinite balls in a line (numbered 1 2 3 ...), and initially all of them is paint black. Now Jim use a brush paint the balls, every time give the integers a B and follow by a char ' w ' or ' B ', ' W ' denotes the Bal L from A to B is painted white, ' B ' denotes is painted black. You were ask to find the longest white ball sequence.

Input

First line was an integer N (<=2000), The Times Jim paint, next N line contain a B c, C can be ' W ' and ' B '.

There is multiple cases, process to the end of file.

Output

Integers the left end of the longest white ball sequence and the right end of a longest white ball sequence (If more tha n One output the small number one). All the input is less than 2^31-1. If No such sequence exists, output "Oh, my God".

Sample Input

4 W8 W3 5 B

Sample Output

8 11
#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)Const intinf=0x7fffffff;//infinitely LargeCharop[3];structinterval{intStart,endn; BOOL operator< (Constinterval& b)Const{        if(start!=B.start)returnstart<B.start; Else            returnendn<B.endn; }};interval val[20001];voidWhiteintAintBint&CNT) {Val[cnt].start=A; Val[cnt].endn=b; CNT++;}voidBlackintAintBint&CNT) {    inttmp=CNT;  for(intI=0; i<cnt;i++)    {        if(val[i].start<a) {if(val[i].endn>=a) {if(val[i].endn<=b) {Val[i].endn=a-1; }                Else{Val[tmp].start=b+1; Val[tmp].endn=Val[i].endn; TMP++; Val[i].endn=a-1; }            }        }        Else if(val[i].start<=b) {if(val[i].endn<=b) {Val[i].start=0; Val[i].endn=-1; }            Else{Val[i].start=b+1; }}} CNT=tmp;}intSolveintCntint&index) {Sort (Val,val+CNT); intmaxn=val[0].endn-val[0].start+1;  for(intI=1; i<cnt;i++)    {        if(val[i].start!=0)        {            if(val[i].start<=val[i-1].endn+1)            {                if(val[i-1].endn<=Val[i].endn) {Val[i].start=val[i-1].start; }                Else{Val[i].start=val[i-1].start; Val[i].endn=val[i-1].endn; }            }            if(val[i].endn-val[i].start+1>MAXN) {MAXN=val[i].endn-val[i].start+1; Index=i; }        }    }    returnMAXN;}intMain () {intN,index,a,b,c;  while(cin>>N) {intCnt=0;  for(intI=0; i<n;i++) {scanf ("%d%d%s",&a,&B,op); if(a>b) {swap (A, b); }            if(op[0]=='W') White (a,b,cnt); ElseBlack (a,b,cnt); } Index=0; if(Solve (Cnt,index)) {cout<<val[index].start<<" "<<val[index].endn<<Endl; }        Elsecout<<"Oh, my god."<<Endl; }    return 0;}

HDU 1199 Color the ball discrete segment tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.