(中等) 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/ ...
随机推荐
- MP3拷贝程序---字节流
package cn.itcast.p7.io.bytestream.test; import java.io.BufferedInputStream; import java.io.Buffered ...
- 使用jquery的js的页面实现例子
var validate;var nodeId="";var modifyappId=""; addExportTaskURL = ctx + "/x ...
- KVC 实战浅析
KVC 就是 key value coding,废话! 今天我们研究的是如何使用它! key value coding : 间接通过字符串类型的key取出对应的属性值 KVC的价值 1.可以访问私有成 ...
- 在写一个iOS应用之前必须做的7件事
转载自:http://www.cocoachina.com/ios/20160316/15685.html 原文:https://medium.com/ios-os-x-development/7-t ...
- PullToRefreshListView上拉加载、下拉刷新 eclipse项目
说明:此项目实在fragment中的,需要依赖library完成,还用到了Xuitls.jar包.使用了Pull解析XML eclipse中的项目: //注意:此刷新功能是使用的第三方的PullToR ...
- Tomcat 虚拟目录映射
最近老是被一个旧Ant工程所困扰,代码版本都改好了测试也通过了,就是打不了war包,一看build.xml 我的天 各种逆天啊....头大.于是乎想起了最基础的tomcat虚拟目录虽是一个很基础的点, ...
- oracle 管理
1.管理数据的用户主要是:sys和system. 区别:(1)sys所有oracle的数据字典的基表和视图都存放在sys用户中,这些基表和视图对于oracle是至关重要的,由数据库自己维护,任何用户都 ...
- android 在代码中使用 #ffffff 模式 设置背景色
differentsum.setBackgroundColor(Color.parseColor("#F3733F"));
- android webview处理下载内容
url = "http://m.mumayi.com/"; WebView = (WebView) findViewById(R.id.webView1); WebView.get ...
- opencv 相关一个很好的博客
http://blog.csdn.net/zouxy09/article/category/1218765 图像卷积与滤波的一些知识点 图像卷积与滤波的一些知识点zouxy09@qq.comhttp: ...