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

坑爹的情况就是最左端是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的更多相关文章

  1. 1019.Line Painting(线段树 离散化)

    1019 离散化都忘记怎么写了 注意两个端点 离散化后用线段树更新区间 混色为-1  黑为2  白为1  因为N不大 最后直接循环标记这一段的颜色查找 #include <iostream> ...

  2. ural1019 Line Painting

    Line Painting Time limit: 2.0 secondMemory limit: 64 MB The segment of numerical axis from 0 to 109  ...

  3. URAL 2025. Line Fighting (math)

    2025. Line Fighting Time limit: 1.0 second Memory limit: 64 MB Boxing, karate, sambo- The audience i ...

  4. Line Painting

    题目大意;说是可以吧一段区间变成白色或者黑色, 区间(0-10^9)初始都是白色,问经过n次操作以后最大的连续白色区间 Problem Description The segment of numer ...

  5. 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)

    原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解    By 岩之痕 目录: 一:综述 ...

  6. 【ACM/ICPC2013】线段树题目集合(一)

    前言:前一段时间在网上找了一个线段树题目列表,我顺着做了一些,今天我把做过的整理一下.感觉自己对线段树了解的还不是很深,自己的算法能力还要加强.光练代码能力还是不够的,要多思考.向队友学习,向大牛学习 ...

  7. 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 ...

  8. 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 求一个最小的 ...

  9. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

随机推荐

  1. WCF的通信

    [ServiceContract]    public interface IContractDemoOne    {        [OperationContract(IsOneWay=true) ...

  2. 有关PHP 10条有用的建议

    1.使用ip2long() 和long2ip()函数来把IP地址转化成整型存储到数据库里. 这种方法把存储空间降到了接近四分之一(char(15)的15个字节对整形的4个字节),计算一个特定的地址是不 ...

  3. C# 框架是什么?MVC是什么 ?工厂模式是什么?设计模式是什么?三层架构是什

    C# 框架是什么?MVC是什么 ?工厂模式是什么?设计模式是什么?三层架构是什么?如果要学我该从何学起??? C# 框架看这里http://download.csdn.net/source/25784 ...

  4. 【HDOJ】1448 The Treasure

    这就是个简单的bfs.真没什么好说的,三维的状态就可以了.每次预处理一下monster的位置,然后再恢复. /* 1924 */ #include <iostream> #include ...

  5. git整理纷乱的历史合并记录

    https://github.com/Epix37/Hearthstone-Deck-Tracker 以上面版本库的master分支为例 父节点1 SHA-1: a21142968282ae49720 ...

  6. zoj 3351 Bloodsucker(概率 dp)

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4530 dp[i]表示现在存在i个吸血鬼要达成目标(全为吸血鬼)天数的数学 ...

  7. Fody

    Fody  https://github.com/Fody/Fody/ 有空还要看下怎么实现的.

  8. bzoj2456

    有趣的题目 空间1mb,所以开数组的算法就不要想了(我一开始没看到……) 仔细读题,然后发现这里他限定众数为出现超过n div 2次 也就是说,这个数可以对应每一个不相同的数消掉,最终还剩下这个数 也 ...

  9. 比较const ,readonly, stitac readonly

    比较const ,readonly, stitac readonly: const和readonly的值一旦初始化则都不再可以改写: const必须在声明时初始化:readonly既可以在声明时初始化 ...

  10. (十三)学习CSS之两个class连一起隔空格和逗号

    1.时常见到css的这两种种写法: a.两个class隔空格连一起: .class1 .class2{......} b.两个class隔逗号连一起: .class1,.class2{......} ...