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. Android studio 安装过程中遇到的问题

    之前用eclipse,想换下studio试试,安装时遇到问题,参考:http://www.cnblogs.com/csulennon/p/4178404.html

  2. Jackson jsonToBean 忽略 Bean中不存在属性的匹配。

    1. jsonToBean时,json中有的字段,bean中没有 无法匹配时,忽略此字段,不抛出异常(默认是抛出异常的) 方案一(局部):在class上加 @JsonIgnoreProperties( ...

  3. Unix IPC之基于共享内存的计数器

    目的 本文主要实现一个基于共享内存的计数器,通过父子进程对其访问. 本文程序需基于<<Unix网络编程-卷2>>的环境才能运行.程序中大写开头的函数为其小写同名函数的包裹函数, ...

  4. Linux学习笔记:ctrl+z、ctrl+c、ctrl+d的区别

    ctrl+c和ctrl+z都是中断命令,但是他们的作用却不一样.    1.ctrl+c是强制中断程序的执行,进程已经终止.   2.ctrl+z的是将任务中止(暂停的意思),但是此任务并没有结束,他 ...

  5. LAMP:用yum安装

    LAMP:用yum安装 Table of Contents 1 什么是LAMP 1.1 L 1.2 A 1.3 M 1.4 P 2 什么是yum 3 如何使用yum 3.1 基本的yum命令 3.1. ...

  6. ETL工具kettle基本使用

    1.下载kettle:https://sourceforge.net/projects/pentaho/files/Data%20Integration/7.0/pdi-ce-7.0.0.0-25.z ...

  7. ****jQuery - 设置HTML内容和属性

    设置内容 - text().html() 以及 val() 我们将使用前一章中的三个相同的方法来设置内容: text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容( ...

  8. **汇总CodeIgniter(CI)的数据库操作函数

    //查询: $query = $this->db_query("SELECT * FROM table"); ================================ ...

  9. 一步一步学习IdentityServer3 (7)

    在介绍自定义用户服务之前先对IdentityServerServiceFactory说明下 Idr3的服务工厂 下面有很多idr3提供的接口服务, 如:ViewService.UserService. ...

  10. ABP zero 3.2 发布

    v3.2.0 (2017-03-07) Common Tenant based UI customizations (allow tenants to upload custom CSS and lo ...