设为首页 加入收藏

TOP

hdu 1199 Color the Ball(离散化线段树)
2014-11-23 21:46:32 来源: 作者: 【 】 浏览:4
Tags: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): 3529 Accepted Submission(s): 874

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

//好事恶习啊,我都快要吐了,第一次做离散化的线段树
#include
#include
#include
#include
using namespace std;
#define N 4040
int a[N],r[N],p[N],c[N],f[N];//r[i]排名i的原位置,p[i]原位置i的排名
int cmp(int i,int j){
    return a[i]=r)return;
    t[k].init(l,r);
    if(l+1>=r)return;
    int md=(l+r)/2;
    build(l,md,k*2);
    build(md,r,k*2+1);//不是md+1(因为md被覆盖)
}
void down(int k){
	if(t[k].l+1==t[k].r)return;
    if(t[k].lz==-1)return;
    t[k*2].lz=t[k*2+1].lz=t[k].lz;
    t[k].lz=-1;
}
void DownAll(int k){
    if(t[k].lz!=-1){
        for(int i=t[k].l;i=t[k].r)return;
    if(l==t[k].l&&r==t[k].r){
        t[k].lz=cr;//标记
        return;
    }
    down(k);
    if(t[k].l+1>=t[k].r)return;

    int md=(t[k].l+t[k].r)/2;
    if(md>=r)update(l,r,cr,k*2);
    else if(l>md)update(l,r,cr,k*2+1);
    else{
        update(l,md,cr,k*2);
        update(md,r,cr,k*2+1);
    }
}
int main(){
    int i,j,k,n;
    int x,y;
	char ch;
    while(~scanf("%d",&n)){
        for(i=j=0;iy-x){x=tx;y=ty;}
        }
        if(x==y) puts("Oh, my god");
        else printf("%d %d\n",x, y-1);

    }
return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 2255 Tree Recovery 下一篇HDU4521:小明系列问题――小明序..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·深入理解 Java 集合 (2025-12-27 07:22:48)
·Java集合框架全面解 (2025-12-27 07:22:45)
·时隔 15 年,巨著《J (2025-12-27 07:22:43)
·定义一个类模板并实 (2025-12-27 06:52:28)
·一文搞懂怎么用C语言 (2025-12-27 06:52:25)