POJ 1436 Horizontally Visible Segments

Horizontally Visible Segments
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 2188 Accepted: 818

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

Source

//又是一个偶数代表点,奇数代表区间的线段树、或许这就是线段树处理区间和点问题的方法吧

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <vector>
#define lson l,m,k<<1
#define rson m+1,r,k<<1|1
#define N 20000
using namespace std;
int st[N<<2];
int n;
struct node
{
    int y1,y2,x1;
};
node xy[8003];
int sot[N],id;
bool visit[8003];
vector<int> hash[8003];
bool cmp(const node&a,const node&b)
{
    return a.x1<b.x1;
}
void build(int l,int r,int k)
{
     st[k]=-1;
    if(l==r)
     return ;
     int m=(l+r)>>1;
    build(lson);
    build(rson);
}
void lookfor(int L,int R,int l,int r,int k)
{
    // printf("id=%d k= %d %d\n",l,r,st[k]);
    if(st[k]!=-1)
    {
        if(!visit[st[k]])
        {
            visit[st[k]]=1;

            hash[id].push_back(st[k]);
        }
        return ;
    }
    if(l==r) return ;
    int m=(l+r)>>1;
    if(L<=m) lookfor(L,R,lson);
    if(R>m) lookfor(L,R,rson);
}
void down(int &k)
{
    st[k<<1]=st[k<<1|1]=st[k];
    st[k]=-1;
}
void updata(int L,int R,int l,int r,int k)
{
    if(L<=l&&R>=r)
    {
       st[k]=id;
       //printf("f=%d %d %d\n",l,r,id);
       return ;
    }
    if(st[k]!=-1)
      down(k);
      int m=(l+r)>>1;
    if(L<=m) updata(L,R,lson);
    if(R>m)  updata(L,R,rson);
}
int main()
{
   int i,j,d;
   int m;
   scanf("%d",&d);
   while(d--)
   {
       scanf("%d",&m);
       n=0;
       for(j=i=0;i<m;i++)
       {
          scanf("%d%d%d",&xy[i].y1,&xy[i].y2,&xy[i].x1);
          sot[j++]=xy[i].y1;sot[j++]=xy[i].y2;
          n=n>xy[i].y1?n:xy[i].y1;
          n=n>xy[i].y2?n:xy[i].y2;
          hash[i].clear();
       }
      n=n<<1;
      build(0,n,1);
      sort(xy,xy+m,cmp);
      for(i=0;i<m;i++)
      {
          memset(visit,0,m*sizeof(bool));
          id=i;
          lookfor(xy[i].y1<<1,xy[i].y2<<1,0,n,1);
          updata(xy[i].y1<<1,xy[i].y2<<1,0,n,1);
      }
      int rc=0;
     // printf("ss");
     for(i=m-1;i>0;i--)//暴力呀
     {
         for(j=0;j<hash[i].size();j++)
            {
                int s=hash[i][j];
                for(int k=0;k<hash[s].size();k++)
                 {
                     for(int l=0;l<hash[i].size();l++)
                       if(hash[s][k]==hash[i][l])
                           rc++;
                 }
            }
     }printf("%d\n",rc);
   }

    return 0;
}

转载于:https://www.cnblogs.com/372465774y/archive/2012/07/19/2599813.html

资源下载链接为: https://pan.quark.cn/s/9648a1f24758 这个HTML文件是一个专门设计的网页,适合在告白或纪念日这样的特殊时刻送给女朋友,给她带来惊喜。它通过HTML技术,将普通文字转化为富有情感和创意的表达方式,让数字媒体也能传递深情。HTML(HyperText Markup Language)是构建网页的基础语言,通过标签描述网页结构和内容,让浏览器正确展示页面。在这个特效网页中,开发者可能使用了HTML5的新特性,比如音频、视频、Canvas画布或WebGL图形,来提升视觉效果和交互体验。 原本这个文件可能是基于ASP.NET技术构建的,其扩展名是“.aspx”。ASP.NET是微软开发的一个服务器端Web应用程序框架,支持多种编程语言(如C#或VB.NET)来编写动态网页。但为了在本地直接运行,不依赖服务器,开发者将其转换为纯静态的HTML格式,只需浏览器即可打开查看。 在使用这个HTML特效页时,建议使用Internet Explorer(IE)浏览器,因为一些老的或特定的网页特效可能只在IE上表现正常,尤其是那些依赖ActiveX控件或IE特有功能的页面。不过,由于IE逐渐被淘汰,现代网页可能不再对其进行优化,因此在其他现代浏览器上运行可能会出现问题。 压缩包内的文件“yangyisen0713-7561403-biaobai(html版本)_1598430618”是经过压缩的HTML文件,可能包含图片、CSS样式表和JavaScript脚本等资源。用户需要先解压,然后在浏览器中打开HTML文件,就能看到预设的告白或纪念日特效。 这个项目展示了HTML作为动态和互动内容载体的强大能力,也提醒我们,尽管技术在进步,但有时复古的方式(如使用IE浏览器)仍能唤起怀旧之情。在准备类似的个性化礼物时,掌握基本的HTML和网页制作技巧非常
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值