hdu 1199 Color the Ball 离散线段树
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
There are multiple cases, process to the end of file.
Output
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
1 4 w
8 11 w
3 5 b
Sample Output
#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 离散线段树的更多相关文章
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
题意:给你n个球排成一行,初始都为黑色,现在给一些操作(L,R,color),给[L,R]区间内的求染上颜色color,'w'为白,'b'为黑.问最后最长的白色区间的起点和终点的位置. 解法:先离散化 ...
- hdu 1199 Color the Ball(离散化线段树)
Color the Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556 Color the ball (技巧 || 线段树)
Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...
- hdu 1556 Color the ball (线段树做法)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a ...
- hdu 1556 Color the ball(非线段树做法)
#include<stdio.h> #include<string.h> ]; int main() { int n,i; int a,b; while(scanf(" ...
- hdu 1199 Color the Ball
http://acm.hdu.edu.cn/showproblem.php?pid=1199 Color the Ball Time Limit: 2000/1000 MS (Java/Others) ...
- hdoj 1556 Color the ball【线段树区间更新】
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- socket系统调用
SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) { int retval; struct socket *sock; in ...
- Django 基于类的视图(CBV)执行流程 CBV 源码分析
一.CBV(基于类的视图) 视图是可以调用的,它接受请求并返回响应,这不仅仅是一个函数,Django提供了一些可以用作视图的类的例子,这些允许您通过继承或mixin来构建视图并重用代码. 基本示例 D ...
- 分析new delete 的本质
在程序设计中,数据可能会存在不同的内存空间,如函数栈 堆 全局变量区 ,今天我们来分析一下C++中堆分配方式和C语言的堆分配方式异同,从而更好的理解new delete本质 C语言使用mall ...
- 【笔记】jQuery插件开发指南
原文链接:http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html (有部分增删和修改) jQuery插件开发模式 软件开发过程中是需要一定 ...
- Codeforces 2B The least round way(dp求最小末尾0)
题目链接:http://codeforces.com/problemset/problem/2/B 题目大意: 给你一个nxn的矩形,找到一条从左上角到右下角的路径,使得该路径上所有数字的乘积的末尾0 ...
- HDU 3613 Best Reward(manacher求前、后缀回文串)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3613 题目大意: 题目大意就是将字符串s分成两部分子串,若子串是回文串则需计算价值,否则价值为0,求分 ...
- python图片处理(三)
ji那天用到了python图片处理中的二值图像的骨架提取,在matlab中通过输入图像的二值,来处理得到图像的骨架, skelimage = bwmorph(im, 'skel', inf); 在ma ...
- algorithm之unique
#include<iostream> #include<algorithm> usingnamespace std; /**< unique函数的算法思想 */ vect ...
- java -D 参数功能解析
我们都知道在启动tomcat或直接执行java命令的时候可以通过参数-XX等来配置虚拟机的大小,同样,也应该留意到java -Dkey=value的参数.那么这个参数是什么作用呢? 使用案例 其实,在 ...
- 网络编程--Socket与ServerSocket
1.服务器端代码 package net; import java.io.PrintStream; import java.net.ServerSocket; import java.net.Sock ...