ZOJ2301(HDU1199) Color the Ball(线段树离散化)
来源:互联网 发布:红叶知弦h同人 编辑:程序博客网 时间:2024/06/06 08:45
http://acm.hdu.edu.cn/showproblem.php?pid=1199
Color the Ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4688 Accepted Submission(s): 1164
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.
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
31 4 w8 11 w3 5 b
Sample Output
8 11
Author
ZHOU, Kai
Source
ZOJ Monthly, February 2005
#include <iostream>#include <algorithm>using namespace std;struct Seg{ int start; int end;};inline int cmp(const Seg a, const Seg b){ return a.start > b.start;}int main(void){ int n, len, tmp; int a, b, tmpsize, maxsize, tstart, tend, ansstart, ansend; char ch; Seg line[20010]; while (cin >> n) { len = 0; while (n--) { cin >> a >> b >> ch; if (a > b) swap(a, b); if (ch == 'w') { line[len].start = a; line[len].end = b; len++; } else { tmp = len; for (int i = 0; i < tmp; ++i) { if (a <= line[i].start && b >= line[i].start && b < line[i].end) { line[i].start = b + 1; continue; } if (a > line[i].start && a <= line[i].end && b >= line[i].end) { line[i].end = a - 1; continue; } if (a > line[i].start && b < line[i].end) { line[len].start = b + 1; line[len].end = line[i].end; line[i].end = a - 1; len++; continue; } if (a <= line[i].start && b >= line[i].end) { line[i].start = -1; line[i].end = -1; } } } } sort(line, line + len, cmp); tstart = -1; tend = -2; maxsize = 0; for (int i = 0; i < len; ++i) { if (line[i].start != -1) { if (line[i].start > tend + 1) { tmpsize = tend - tstart + 1; if (tmpsize > maxsize) { maxsize = tmpsize; ansstart = tstart; ansend = tend; } tstart = line[i].start; tend = line[i].end; } else tend = tend > line[i].end ? tend : line[i].end; } } tmpsize = tend - tstart + 1; if (tmpsize > maxsize) { maxsize = tmpsize; ansstart = tstart; ansend = tend; } if (maxsize == 0) cout << "Oh, my god" << endl; else cout << ansstart << " " << ansend << endl; } return 0;}
0 0
- ZOJ2301(HDU1199) Color the Ball(线段树离散化)
- ZOJ2301(HDU1199) Color the Ball(离散化)
- zoj2301||hdu1199(线段树染色+离散)
- hdu1199:color the ball(离散化)
- HDU1199-Color the Ball
- hdu 1199 Color the Ball(离散化线段树)
- zoj 2301 Color the Ball(区间染色,线段树+离散化)
- hdu 1199 Color the Ball (线段树区间合并,离散化)
- hdu 1199 Color the ball(线段树离散化区间染色)
- HDU 1199 Color the Ball(线段切割 离散化思想)
- HDU 1199.Color the Ball【区间操作(可以用离散化线段树)】【暴力求解】【5月26】
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
- zoj 2301 || hdu 1199 Color the Ball 线段树 离散化
- Color the ball (线段树)
- Color the ball(线段树)
- Color the ball(线段树)
- HDU 1199 Color the Ball(离散化入门+非线段树做法)
- HDOJ Color the ball (线段树方法)
- uva11636
- 多个线程之间共享数据的方式探讨(七)
- access数据库插入日期变成1905-6-23
- uva11039(贪心)
- uva12657 boxes in a line
- ZOJ2301(HDU1199) Color the Ball(线段树离散化)
- HTML控件属性
- 八皇后回溯递归 40行不到
- poj1833 排列
- Camera Calibration 学习总结
- eclipse不自动弹出提示(alt+/快捷键失效)
- kuangbin带你飞——专题1——简单搜索E——求有01组成的十进制数问题
- u-boot-2015.01在tq2440上的初步移植
- android开发,手指触摸屏幕后,dialog消失了怎么办?