水博客,水一水。

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. 写入时复制(Copy-on-write)机制
  2. 树形控件CTreeCtrl的使用详解(一)
  3. Coursera公开课笔记: 斯坦福大学机器学习第七课“正则化(Regularization)”
  4. win10安装docker desktop之后没有ADVANCED选项解决办法
  5. 数跑科技联合阿里云创造基于云原生的无边界数字新体验
  6. LeetCode 1878. 矩阵中最大的三个菱形和(模拟)
  7. storm和vgj vgj_VGJ改名J.Storm专注北美赛区 收编新队
  8. Alameda:最初同意对Reef投资8000万美元,但支付2000万美元后Reef拒绝了随后的交易
  9. C#存取数据为所欲为(二)
  10. awk的基本使用方法
  11. nginx 启动失败
  12. Spring设置定时器配置
  13. 大众点评运维架构详大揭秘!
  14. 1060 Are They Equal (25 分)科学计数法,stl中string的各种函数用法
  15. 微信小程序获取用户头像和昵称能力调整!新的代替方案!
  16. H5 font标签及其属性
  17. python编写程序计算梯形面积公式_肿么用c语言编写程序梯形面积
  18. 手机vnc连接云服务器,云服务器管理终端(VNC连接)说明
  19. 图解多线程设计模式pdf_图解Java多线程设计模式pdf
  20. getch方法_linux 下getch()函数实现

热门文章

  1. 什么是白箱测试、黑箱测试、回归测试?
  2. Chinese Std GBT7714-2015.ens EndNote 样式文件
  3. vulnhub-Tiki - 类oscp靶机攻略1
  4. Signature on Pocket PC
  5. JVM -- JVM内存结构:程序计数器、虚拟机栈、本地方法栈、堆、方法区(二)
  6. php短信报警直到响应,Cacti实现短信报警
  7. 致远oa系统unix 服务器,致远oa手机客户端服务器
  8. Android 实现欢迎界面
  9. WORD2010文档里面突然不能输入汉字的解决办法
  10. List集合排序Collections.sort()方法的一个容易忽略的小问题