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下内存泄漏工具

    概述 内存泄漏(memory leak)指由于疏忽或错误造成程序未能释放已经不再使用的内存的情况,在大型的.复杂的应用程序中,内存泄漏是常见的问题.当以前分配的一片内存不再需要使用或无法访问时,但是却 ...

  2. ASP.NET 实现Base64文件流下载PDF

    因为业务需要调用接口获取的是 Base64文件流 需要提供给客户下载PDF文档 源码部分借鉴网上,具体地址忘记了. //Base64文件流 byte[] buffer = Convert.FromBa ...

  3. 关于 JVM 内存的 N 个问题(转)

    JVM的内存区域是怎么划分的? JVM的内存划分中,有部分区域是线程私有的,有部分是属于整个JVM进程:有些区域会抛出OOM异常,有些则不会,了解JVM的内存区域划分以及特征,是定位线上内存问题的基础 ...

  4. day07作业

    import java.util.Scanner; class SsqGame { public static void main(String[] args) { int total = 0;//买 ...

  5. No.2 selenium学习之路之八种基本定位

    selenium的八种定位方式 1.通过id定位     find_element_by_id() send_keys() 输入框输入字符串 click()  鼠标点击事件 注:send_keys输入 ...

  6. 浮动元素垂直居中,bootstrap栅格布局垂直居中

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. POJ 3286 How many 0's(数位DP模板)

    题目链接:http://poj.org/problem?id=3286 题目大意: 输入n,m,求[n,m]的所有数字中,0出现的总数是多少,前导零不算. 解题思路: 模板题,设dp[pos][num ...

  8. new[] 到底做了什么?

    #include<iostream> #include<cstdlib> using std::cout; using std::endl; using std::hex; c ...

  9. IIS部署asp.net MVC 出现错误 403.14-Forbidden解决办法

    可能性一: <system.webServer>   <validationvalidateIntegratedModeConfiguration="false" ...

  10. [水煮 ASP.NET Web API2 方法论](1-4)从 MVC Controller 链接到 API Controller 以及反向链接

    问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controller 的直接链接,或者反向链接. 解决方案 可以使用 System.Web.Htt ...