(中等) POJ 1436 Horizontally Visible Segments , 线段树+区间更新。
Description
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib> #define lson L,M,po*2
#define rson M+1,R,po*2+1 using namespace std; const int N=*; int COL[**];
bool map1[][]; void pushDown(int po)
{
if(COL[po]>=)
{
COL[po*]=COL[po*+]=COL[po];
COL[po]=-;
}
} void update(int ul,int ur,int ut,int L,int R,int po)
{
if(ul<=L&&ur>=R)
{
COL[po]=ut; return;
} pushDown(po); int M=(L+R)/; if(ul<=M)
update(ul,ur,ut,lson);
if(ur>M)
update(ul,ur,ut,rson); if(COL[po*]==COL[po*+]) //这里算是一个剪枝操作,可以减少递归次数。
COL[po]=COL[po*];
else
COL[po]=-;
} void query(int ql,int qr,int qt,int L,int R,int po)
{
if(COL[po]!=-)
{
map1[qt][COL[po]]=map1[COL[po]][qt]=;
return;
} if(L==R)
return; int M=(L+R)/; if(ql<=M)
query(ql,qr,qt,lson);
if(qr>M)
query(ql,qr,qt,rson);
} struct state
{
int y1,y2,x1;
}; state sta[]; int cmp(const void*a,const void*b)
{
return (*(state*)a).x1-(*(state*)b).x1;
} int main()
{
int d;
cin>>d; int n; while(d--)
{
memset(map1,,sizeof(map1));
memset(COL,,sizeof(COL)); cin>>n; for(int i=;i<n;++i)
scanf("%d %d %d",&sta[i].y1,&sta[i].y2,&sta[i].x1); qsort(sta,n,sizeof(state),cmp); for(int i=;i<=n;++i)
{
query(sta[i-].y1*,sta[i-].y2*,i,,N,);
update(sta[i-].y1*,sta[i-].y2*,i,,N,);
} long long ans=; for(int i=;i<=n;++i) //直接暴力求解,居然不超时。。。
for(int j=i+;j<=n;++j)
if(map1[i][j])
for(int k=j+;k<=n;++k)
if(map1[i][k]&&map1[j][k])
++ans; cout<<ans<<endl;
} return ;
}
(中等) POJ 1436 Horizontally Visible Segments , 线段树+区间更新。的更多相关文章
- POJ 1436.Horizontally Visible Segments-线段树(区间更新、端点放大2倍)
水博客,水一水. Horizontally Visible Segments Time Limit: 5000MS Memory Limit: 65536K Total Submissions: ...
- POJ 1436 Horizontally Visible Segments (线段树·区间染色)
题意 在坐标系中有n条平行于y轴的线段 当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交 就视为它们是可见的 问有多少组三条线段两两相互可见 先把全部线段存下来 并按x ...
- POJ 1436 Horizontally Visible Segments(线段树)
POJ 1436 Horizontally Visible Segments 题目链接 线段树处理染色问题,把线段排序.从左往右扫描处理出每一个线段能看到的右边的线段,然后利用bitset维护枚举两个 ...
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ 1436 Horizontally Visible Segments
题意: 有一些平行于y轴的线段 ,两条线段称为互相可见当且仅当存在一条水平线段连接这两条 与其他线段没交点. 最后问有多少组 3条线段,他们两两是可见的. 思路: 线段树,找出两两可见的那些组合, ...
- poj 2528 Mayor's posters 线段树区间更新
Mayor's posters Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...
- (中等) UESTC 360 Another LCIS ,线段树+区间更新。
Description: For a sequence S1,S2,⋯,SN, and a pair of integers (i,j), if 1≤i≤j≤N and Si<Si+1<S ...
- poj 2777 Count Color(线段树 区间更新)
题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释, 参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/ ...
随机推荐
- opencv-----基本数据类型
OpenCV提供了多种基本数据类型.可以在"…/OpenCV/cxcore/include"目录下的cxtypes.h文件中查看其详细定义. CvPoint是一个包含integer ...
- php取随机数 explode劫取字符串 时间定义随机数
php取随机数 <?phpfunction randomkeys($length){ $pattern='1234567890'; for($i=0;$i<$length;$i++) { ...
- [转]修改hosts文件不起作用
http://wayne173.iteye.com/blog/1876565 今天遇到个很奇怪的问题,在hosts文件里添加了一些域名指向后,发现根本没起作用,后来还发现个细节,就是hosts文件左下 ...
- C++头文件#include<bits/stdc++.h>
一句话的事,直截了当——#include<bits/stdc++.h>包含C++的所有头文件 参考网站(点击):http://www.tuicool.com/articles/m6neUj ...
- postfix中recipient/client/sender/helo四者的区别<转载>
postfix在main.cf中用下面四个做限制,那么这四者到底有什么区别? smtpd_recipient_restrictions smtpd_client_restrictions smtpd_ ...
- iOS原生refresh(UIRefreshControl)
转载:http://www.2cto.com/kf/201504/392431.html // // ViewController.m // 代码自定义cell // // Created by ma ...
- (转)MATLAB入门教程
MATLAB入门教程 1.MATLAB的基本知识 1-1.基本运算与函数 在MATLAB下进行基本数学运算,只需将运算式直接打入提示号(>>)之後,并按入Enter键即可.例如: ...
- 转:Visual Studio进行Web性能测试- Part II
原文作者:Ambily.raj 对于一个多用户的应用程序,性能是非常重要的.性能不仅是执行的速度,它包括负载和并发方面.Visual Studio是可以用于性能测试的工具之一.Visual Studi ...
- PAT (Advanced Level) 1051. Pop Sequence (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- Mysql 中文乱码问题完美解决方案
MySQL会出现中文乱码的原因不外乎下列几点: 1.server本身设定问题,例如还停留在latin1 2.table的语系设定问题(包含character与collation) 3.客户端程式(例如 ...