水博客,水一水。

Horizontally Visible Segments
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 6290   Accepted: 2287

Description

There is a number of disjoint vertical line segments in the plane. We say that two segments are horizontally visible if they can be connected by a horizontal line segment that does not have any common points with other vertical segments. Three different vertical segments are said to form a triangle of segments if each two of them are horizontally visible. How many triangles can be found in a given set of vertical segments?

Task

Write a program which for each data set:

reads the description of a set of vertical segments,

computes the number of triangles in this set,

writes the result.

Input

The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 20. The data sets follow.

The first line of each data set contains exactly one integer n, 1 <= n <= 8 000, equal to the number of vertical line segments.

Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:

yi', yi'', xi - y-coordinate of the beginning of a segment, y-coordinate of its end and its x-coordinate, respectively. The coordinates satisfy 0 <= yi' < yi'' <= 8 000, 0 <= xi <= 8 000. The segments are disjoint.

Output

The output should consist of exactly d lines, one line for each data set. Line i should contain exactly one integer equal to the number of triangles in the i-th data set.

Sample Input

1
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3

Sample Output

1

题意:输入n表示有n条线段,n行每行输入y1,y2,x表示线段的下端点,上端点以及线段的位置(横坐标位置),对于第i条线段和第k条线段如果用一条平行线能够经过它们并且在它们之间不经过其他线段,则称这两条线段互为可见,求有多少3条线段两两可见(懒得写题意,直接贴的别人的)

代码:

  1 //线段树区间更新,端点放大2倍
  2 #include<iostream>
  3 #include<cstdio>
  4 #include<cstring>
  5 #include<algorithm>
  6 #include<cmath>
  7 #include<cstdlib>
  8 using namespace std;
  9 typedef long long ll;
 10 const int maxn=8e3+10;
 11
 12 #define lson l,m,rt<<1
 13 #define rson m+1,r,rt<<1|1
 14
 15 int col[maxn<<2];
 16 bool mp[maxn][maxn];
 17
 18 struct node{
 19     int y1,y2,x,id;
 20 }line[maxn];
 21
 22 bool cmp(node a,node b)
 23 {
 24     return a.x<b.x;
 25 }
 26
 27 void init()
 28 {
 29     memset(mp,0,sizeof mp);
 30     memset(line,0,sizeof line);
 31     memset(col,0,sizeof col);
 32 }
 33
 34 void pushdown(int rt)
 35 {
 36     if(col[rt]){
 37         col[rt<<1]=col[rt<<1|1]=col[rt];
 38         col[rt]=0;
 39     }
 40 }
 41
 42 void update(int L,int R,int c,int l,int r,int rt)
 43 {
 44     if(L<=l&&r<=R){
 45         col[rt]=c;
 46         return ;
 47     }
 48
 49     pushdown(rt);
 50     int m=(l+r)>>1;
 51     if(L<=m) update(L,R,c,lson);
 52     if(R> m) update(L,R,c,rson);
 53 }
 54
 55 void query(int L,int R,int c,int l,int r,int rt)
 56 {
 57     if(col[rt]){
 58         mp[c][col[rt]]=1;
 59         return ;
 60     }
 61
 62     if(l==r){
 63         return ;
 64     }
 65
 66     int m=(l+r)>>1;
 67     if(L<=m) query(L,R,c,lson);
 68     if(R> m) query(L,R,c,rson);
 69 }
 70
 71 int main()
 72 {
 73     int t;
 74     scanf("%d",&t);
 75     while(t--){
 76         init();
 77         int n;
 78         scanf("%d",&n);
 79         int N=-1;
 80         for(int i=1;i<=n;i++){
 81             scanf("%d%d%d",&line[i].y1,&line[i].y2,&line[i].x);
 82             line[i].id=i;line[i].y1*=2;line[i].y2*=2;N=max(N,max(line[i].y1,line[i].y2));
 83         }
 84         sort(line+1,line+1+n,cmp);//按x轴从小到大排序,降维,只对y轴进行建树
 85         for(int i=1;i<=n;i++){
 86             query(line[i].y1,line[i].y2,line[i].id,0,N,1);
 87             update(line[i].y1,line[i].y2,line[i].id,0,N,1);
 88         }
 89         int ans=0;
 90         for(int i=1;i<=n;i++){
 91             for(int j=1;j<=n;j++){
 92                 if(mp[i][j]){
 93                     for(int k=1;k<=n;k++){
 94                         if(mp[i][k]&&mp[k][j]) ans++;
 95                     }
 96                 }
 97             }
 98         }
 99         printf("%d\n",ans);
100     }
101 }

转载于:https://www.cnblogs.com/ZERO-/p/10951596.html

POJ 1436.Horizontally Visible Segments-线段树(区间更新、端点放大2倍)相关推荐

  1. POJ 2777 - Count Color(线段树区间更新+状态压缩)

    题目链接 https://cn.vjudge.net/problem/POJ-2777 [题意] 有一个长度为 LLL 的区间 [1,L][1,L][1,L] ,有 TTT 种颜色可以涂,有 QQQ ...

  2. poj 1436 Horizontally Visible Segments

    题目大意: 在一个平面内,有一些竖直的线段,若两条竖直线段之间可以连一条水平线,这条水平线不与其他竖直线段相交,称这两条竖直线段为"相互可见"的.若存在三条竖直线段,两两" ...

  3. POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新

    直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...

  4. hdu 5692 Snacks(dfs序+线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5692 解题思路:这道题是树节点的点权更新,而且涉及到子树,常用的思路是利用dfs序,用线段树来对区间进 ...

  5. hdu 1698(线段树区间更新)

    解题思路:线段树区间更新水题. #include<iostream> #include<cstdio> #include<cstring> using namesp ...

  6. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  7. hdu 3966(树链剖分+线段树区间更新)

    传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.c ...

  8. Just a Hook(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 In the game of DotA, Pudge's meat hook is actual ...

  9. hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新

    #1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,"模拟都市"是他们非常喜欢的一个游戏 ...

  10. CodeForces - 272C Dima and Staircase (线段树区间更新)

    题意: 见以下样例,给出 5 个区间,每个区间的高度已知.一共 4 次操作.每次操作都是从最左边开始向下垒一个宽为 w 高为h 的木块,过程见下图. 问每次垒木块的高度是多少? Input 5 1 2 ...

最新文章

  1. 用mendeley在word中插入文献_Mendeley在Word添加工具栏和插入和删除文献的方法 | 科研动力...
  2. 面试上海阿里体育的一道面试题: 设计模式,多态
  3. 软件工程概论 课堂练习 第3次作业6【流图;计算环形复杂度;找独立路径】
  4. 这些被同事喷的JS代码风格你写过多少?
  5. [RabbitMQ]常用命令
  6. alot英文怎么读_很多的英文怎么说
  7. docker中安装了RabbitMQ后无法访问其Web管理页面
  8. C结构体之位域(位段)
  9. C++雾中风景12:聊聊C++中的Mutex,以及拯救生产力的Boost
  10. centos6.5系统不支持 mysql_centos6.5系统下面MySql数据库的安装
  11. zynq开发系列5:通过AXI GPIO的中断实现PL端按键控制PS端LED(SDK开发详解)
  12. JavaEE——Mybatis(5)--resultMap自定义结果集封装
  13. 箭头函数及其this指向
  14. SIM800C长短信学习笔记
  15. android 新浪微博平台开发之 ——授权登录
  16. 【EE】案例分享-如何设计继电器电路?
  17. 群控进化史,黑产攻击效率提升带来的防守困境
  18. [ML] Genetic Algorithm 理论概述
  19. SIMATIC S7-300 Profibus通讯——(2)EM277与S7-300通讯
  20. Python学习 Day37 jQuery框架01

热门文章

  1. AI 让已故歌手重聚,再发4首原创新歌
  2. java中交换机的作用_交换机链路聚合在网络中的作用
  3. 小ck活动机器人包包_古力娜扎空降“小ck”线下门店,手上的包包亮了,仙气又便宜!...
  4. js输出类面试题(二)
  5. 本地计算机策略打不开怎么办,我的电脑的本地组策略编辑器怎么打不开?
  6. android 开发之activity 启动流程《一》
  7. Pytorch入门实战(7):基于BERT实现文本隐喻二分类(Kaggle入门题目)
  8. zabbix三种常用报警方式:邮件、微信和短信报警
  9. php ansiix99mac,华擎推出X99E-ITX/ac主板,终于可以把Haswell-E装进小钢炮
  10. vlan划分-通过物理接口实现vlan通信