URAL 1019 - Line Painting
跟前面某个题一样,都是区间染色问题,还是用我的老方法,区间离散化+二分区间端点+区间处理做的,时间跑的还挺短


坑爹的情况就是最左端是0,最右端是1e9,区间求的是开区间
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef struct
{
int l;
int r;
bool color;
}seg;
seg a[5005];
int t[10005];
int d[10005],ct;
int f[10005]; int find(int x,int n)
{
int l=0,r=n-1,mid=(l+r)/2;
while(l<r)
{
if(x>d[mid])l=mid+1;
else r=mid;
mid=(l+r)/2;
}
return mid;
} int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
char e;
scanf("%d %d %c",&t[2*i],&t[2*i+1],&e);
a[i].l=t[2*i];
a[i].r=t[2*i+1];
a[i].color=(e=='w')?0:1;
}
t[2*n]=0;t[2*n+1]=1e9;
sort(t,t+2*n+2);
ct=0;
d[ct++]=t[0];
for(int i=1;i<2*n+2;i++)
if(t[i]!=t[i-1])
d[ct++]=t[i];
memset(f,0,sizeof(f));
for(int i=0;i<n;i++)
{
int L=find(a[i].l,ct);
int R=find(a[i].r,ct);
for(int j=L;j<R;j++)
f[j]=a[i].color;
}
int left=0;
int max=0,a1,a2;
for(int i=0;i<ct;i++)
{
if(f[i]==1||d[i]==1e9)
{
if(left==d[i]){left=d[i+1];continue;}
else {
if(d[i]-left>max){
max=d[i]-left;
a1=left;
a2=d[i];
}
left=d[i+1];
}
}
}
printf("%d %d\n",a1,a2);
return 0;
}
URAL 1019 - Line Painting的更多相关文章
- 1019.Line Painting(线段树 离散化)
1019 离散化都忘记怎么写了 注意两个端点 离散化后用线段树更新区间 混色为-1 黑为2 白为1 因为N不大 最后直接循环标记这一段的颜色查找 #include <iostream> ...
- ural1019 Line Painting
Line Painting Time limit: 2.0 secondMemory limit: 64 MB The segment of numerical axis from 0 to 109 ...
- URAL 2025. Line Fighting (math)
2025. Line Fighting Time limit: 1.0 second Memory limit: 64 MB Boxing, karate, sambo- The audience i ...
- Line Painting
题目大意;说是可以吧一段区间变成白色或者黑色, 区间(0-10^9)初始都是白色,问经过n次操作以后最大的连续白色区间 Problem Description The segment of numer ...
- 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)
原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解 By 岩之痕 目录: 一:综述 ...
- 【ACM/ICPC2013】线段树题目集合(一)
前言:前一段时间在网上找了一个线段树题目列表,我顺着做了一些,今天我把做过的整理一下.感觉自己对线段树了解的还不是很深,自己的算法能力还要加强.光练代码能力还是不够的,要多思考.向队友学习,向大牛学习 ...
- Aizu The Maximum Number of Customers
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A The Maximum Number of Customers Ide ...
- URAL 1948 H - The Robot on the Line 二分 + 数学
http://acm.hust.edu.cn/vjudge/contest/126149#problem/H 给定一条二次函数 f (x) = a * x * x + b * x + c 求一个最小的 ...
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
随机推荐
- A simple json-rpc case for bitcoin blockchains
#!/usr/bin/env python import json import jsonrpc import requests #url = "http://user:password@i ...
- maven打包源代码sources.jar和javadoc.jar帮助文档
maven中如何打包源代码 *-sources.jar 方式一 : 命令行方式 进入cmd命令行,进入项目工程pom.xml所在路径目录,运行mvn source:jar 和 mvn javado ...
- 解决windows下vim方向键变成 ABCD 的问题
一.问题描述: windows下面要安装git --> 安装了 msys2 -->安装并更新了 vim(7.4),然后在使用过程中发现vim不能使用 BACKSPACE 键,按方向键会打 ...
- set xact_abort 用法
默认行为 默认为SET XACT_ABORT OFF,没有事务行为. SET XACT_ABORT ON SET XACT_ABORT ON分为两种: 1.总体作为一个事务,整体提交或整体回滚,格式为 ...
- OK335xS davinci mdio driver hacking
/******************************************************************************* * OK335xS davinci m ...
- EF框架step by step(8)—Code First DataAnnotations(2)
上一篇EF框架step by step(7)—Code First DataAnnotations(1)描述了实体内部的采用数据特性描述与表的关系.这一篇将用DataAnnotations描述一下实体 ...
- POJ3616 Milking Time 简单DP
注意0,1,.....,N是时间点,i~i+1是时间段 然后就是思路:dp[i]代表到时间点 i 获得的最大价值, 1:dp[i]=max(dp[i],dp[s-r]+e),表示有以s为开头,i为结尾 ...
- VirtualBox Headless启动虚拟机
习惯了在Windows上来学习和娱乐,所以不能切换到Linux系统. 为了Linux编程,我首先尝试了wubi在Windows上安装双系统,但是发现本来启动很快的Windows8安装了双系统之后,系统 ...
- 【UR #12】实验室外的攻防战(BIT)
[题目链接] http://uoj.ac/problem/180 [题意] 给定两个1..n的排列AB,只有当ai<ai+1才能交换ai和ai+1,问是否能够将A转换为B. [思路] 令a[i] ...
- uva 11997 K Smallest Sums 优先队列处理多路归并问题
题意:K个数组每组K个值,每次从一组中选一个,共K^k种,问前K个小的. 思路:优先队列处理多路归并,每个状态含有K个元素.详见刘汝佳算法指南. #include<iostream> #i ...