C - Color the Ball

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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 <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0) const int inf=0x7fffffff; //无限大
char op[];
struct interval
{
int start,endn;
bool operator < (const interval& b)const{
if(start!=b.start)
return start<b.start;
else
return endn<b.endn;
}
};
interval val[];
void white(int a,int b,int& cnt)
{
val[cnt].start=a;
val[cnt].endn=b;
cnt++;
}
void black(int a,int b,int& cnt)
{
int tmp=cnt;
for(int i=;i<cnt;i++)
{
if(val[i].start<a)
{
if(val[i].endn>=a)
{
if(val[i].endn<=b)
{
val[i].endn=a-;
}
else
{
val[tmp].start=b+;
val[tmp].endn=val[i].endn;
tmp++;
val[i].endn=a-;
}
}
}
else if(val[i].start<=b)
{
if(val[i].endn<=b)
{
val[i].start=;
val[i].endn=-;
}
else
{
val[i].start=b+;
}
}
}
cnt=tmp;
}
int solve(int cnt,int& index)
{
sort(val,val+cnt);
int maxn=val[].endn-val[].start+;
for(int i=;i<cnt;i++)
{
if(val[i].start!=)
{
if(val[i].start<=val[i-].endn+)
{
if(val[i-].endn<=val[i].endn)
{
val[i].start=val[i-].start;
}
else
{
val[i].start=val[i-].start;
val[i].endn=val[i-].endn;
}
}
if(val[i].endn-val[i].start+>maxn)
{
maxn=val[i].endn-val[i].start+;
index=i;
}
}
}
return maxn;
}
int main()
{
int n,index,a,b,c;
while(cin>>n)
{
int cnt=;
for(int i=;i<n;i++)
{
scanf("%d%d%s",&a,&b,op);
if(a>b)
{
swap(a,b);
}
if(op[]=='w')
white(a,b,cnt);
else
black(a,b,cnt);
}
index=;
if(solve(cnt,index))
{
cout<<val[index].start<<" "<<val[index].endn<<endl;
}
else
cout<<"Oh, my god"<<endl;
}
return ;
}
 

hdu 1199 Color the Ball 离散线段树的更多相关文章

  1. ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和

    题意:给你n个球排成一行,初始都为黑色,现在给一些操作(L,R,color),给[L,R]区间内的求染上颜色color,'w'为白,'b'为黑.问最后最长的白色区间的起点和终点的位置. 解法:先离散化 ...

  2. hdu 1199 Color the Ball(离散化线段树)

    Color the Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  3. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. hdu 1556 Color the ball (技巧 || 线段树)

    Color the ballTime Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  5. HDU 1556 Color the ball(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...

  6. hdu 1556 Color the ball (线段树做法)

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a ...

  7. hdu 1556 Color the ball(非线段树做法)

    #include<stdio.h> #include<string.h> ]; int main() { int n,i; int a,b; while(scanf(" ...

  8. hdu 1199 Color the Ball

    http://acm.hdu.edu.cn/showproblem.php?pid=1199 Color the Ball Time Limit: 2000/1000 MS (Java/Others) ...

  9. hdoj 1556 Color the ball【线段树区间更新】

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. linux音频alsa-uda134x驱动分析之二(时钟)

    Audio Clocking音频时钟============== This text describes the audio clocking terms in ASoC and digital au ...

  2. html5拖拽初窥

    说到拖动,大概有两种方式,一种是js实现,之前已经介绍过,今天来讲解另外一种方式,那就是使用html5实现拖动. css样式 .box { width: 200px; height: 200px; b ...

  3. web性能优化之js图片懒加载

    html <div class="container"> <ul> <li> <div id="first" clas ...

  4. DOS命令基础,包涵DOS库说明书

    20种常用的DOS命令小结 作者: 字体:[增加 减小] 类型:转载   DOS命令总共大约有一百个(包括文本编辑.查杀病毒.配置文件.批处理等),我们这里详细介绍二十个常用的DOS命令     先介 ...

  5. Form 源码

    1. is_valid如果返回值如果为真 证明验证成功 意味着self.is_bound为True 和 self.errors为False def is_valid(self): return sel ...

  6. wpf mvvm模式下的image绑定

    view文件 <Image Grid.Column="2" Width="48" Height="64" Stretch=" ...

  7. 【直播预告】云栖直播:阿里热修复产品HotFix2.0升级详解

    全面——你知道吗?1891年,卡尔森纳做出的第一把瑞士军刀,只有螺丝刀和开罐器.经过一代又一代能工巧匠的打磨,这把刀陆续增加了锯子.剪刀.镊子.放大镜.改锥,甚至内藏激光.LED手电筒.USB记忆碟等 ...

  8. 非ROOT用户不能识别声卡问题

    将非ROOT用户加入到audio组中即可 sudo usermod -a -G audio usrname

  9. 【LOJ】#2065. 「SDOI2016」模式字符串

    题解 按秩合并怎么清数组对我来说真是世纪性难题 我们很熟练地想到点分,如果我们认为某个点到重心是正着读的,由于它的深度固定,它的串也是固定的,我们只要预处理出所有长度正着重复的串,反着重复的串,和它们 ...

  10. SQLite数据库、ListView控件的使用

    android下数据库的创建(重点) 在Android平台上,集成了一个轻量级嵌入式关系型数据库—SQLite,SQLite3支持 NULL.INTEGER.REAL(浮点数字).TEXT(字符串文本 ...