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 ...
随机推荐
- liunx系统top命令详解
ps: 1.按1可以进行 CPU各个和总CPU汇总的切换2.cpu0是最关键的,总控管理各个CPU 3.默认情况下仅显示比较重要的 PID.USER.PR.NI.VIRT.RES.SHR.S.%CPU ...
- python 之sqlite3库学习
# -*- coding:utf-8 -*- # 导入SQLite驱动:>>> import sqlite3# 连接到SQLite数据库# 数据库文件是test.db# 如果文件不存 ...
- 二十一、springboot之定制URL匹配规则(项目中遇到的问题:get方式传参,带有小数点,被忽略)
一.问题描述: get方式传参,在传送价格,积分时(带有小数点),debug后台微服务接受到的参数,却不带小数点,如:price是0.55,后台接受后却是0 二.解决 在WebConfiguratio ...
- CentOS7网卡改名
# vi /etc/sysconfig/grub 修改上面内容中的GRUB_CMDLINE_LINUX的值,增加net.ifnames=0 biosdevname=0 执行:grub2-mkconfi ...
- wiki confluence安装
注意:安装前请先确认内存 至少2G 1.上传 atlassian-confluence-5.9.3-x64.bin 文件,修改权限 chmod 777 atlassian-confluence-5.9 ...
- Centos之常见目录作用介绍
我们先切换到系统根目录 / 看看根目录下有哪些目录 [root@localhost ~]# cd / [root@localhost /]# ls bin dev home lib64 mn ...
- django 建立一个简单的应用
本人的用的版本是python 2.7.3和django 1.10.5,Windows10系统 1.首先通过命令建立项目和app 找到django的安装路径,我的路径是:C:\Python27\Lib\ ...
- CCF CSP 201409-3 字符串匹配
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201409-3 字符串匹配 问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那 ...
- 基于Json.NET自己实现MVC中的JsonValueProviderFactory
写了博文ASP.NET MVC 3升级至MVC 5.1的遭遇:“已添加了具有相同键的项”之后,继续看着System.Web.Mvc.JsonValueProviderFactory的开源代码. 越看越 ...
- 【LOJ】#2041. 「SHOI2015」聚变反应炉
题解 这显然是一道题拆成两道 然后我胡乱分析了一波,决定第一题就用点度贪心(反正散播的能量肯定能被使用),然后过了 第二题开始mengbier 设\(f_u\)表示第u个点在父亲发动之后才发动的最小价 ...