(中等) 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/ ...
随机推荐
- Java BigDecimal Class
Using BigDecimal to perform precise calculations with floats. BigDecimal is a class type. So declare ...
- fidder 调试本地文件
- centos yum源问题
在配置CentOS-6.0-x86_64-bin-DVD2.iso作为本地yum源的时候,碰到相当多的问题: ----------------------------------------- 问题 ...
- [转]解决LinearLayout中控件不能居右对齐
在LinearLayout布局时使用右对齐(android:layout_gravity="right")控件对齐方式不生效,需要设置 android:layout_weight= ...
- AI 人工智能 探索 (三)
三类子弹的设计 using UnityEngine; using System.Collections; public class AI : AssembleModel { private Hasht ...
- 线程带参数的Udp接收
//work wk = new work(ReadUdpDate); ParameterizedThreadStart parmThre = new ParameterizedThreadStart( ...
- windows下,emacs的配置文件在哪儿?
配置文件_Emacs在你的家目录下"C:/Documents and Settings/username/Application Data". 在Window 7下,配置文件目录在 ...
- String转float
float mTotalhour = Float.parseFloat(mTotalHourEt.getText().toString().trim());
- maven编码 gbk 的不可映射字符解决办法
出现这个问题修改一下pom文件的编译配置就好了. <plugin> <groupId>org.apache.maven.plugins</groupId> < ...
- 滑雪(ski)
滑雪(ski) 题目描述 Michael喜欢滑雪.这并不奇怪,因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...