POJ-1436Horizontally Visible Segments
来源:互联网 发布:node express 中间件 编辑:程序博客网 时间:2024/06/05 04:48
能用线段树做,但是n3也过
把坐标 * 2 来区别,端点和非端点
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct edge{ int y1,y2,x,id;}E[8008];int node[8008*8];bool ok[8008][8008];inline bool cmp(edge a,edge b){ return a.x<b.x;}void push_down(int root){ if (node[root] == 0) return; node[root*2] = node[root]; node[root*2+1] = node[root]; node[root] = 0;}void solve(int root,int xbegin,int xend,int qbegin,int qend,int id){ if (qend < xbegin||xend<qbegin) return; if (qbegin <= xbegin && xend <= qend) { if (node[root]!=0) { ok[id][node[root]] = true; ok[node[root]][id] = true; node[root] = id; return; } node[root] = id; } else push_down(root); int mid = (xbegin + xend) /2; if (xbegin == xend) return; solve(root*2,xbegin,mid,qbegin,qend,id); solve(root*2+1,mid+1,xend,qbegin,qend,id);}int main(){ int T; cin >> T; int y1,y2,x; while (T--) { int N; cin >> N; memset(node,0,sizeof(node)); memset(ok,false,sizeof(ok)); int max_y = 0; for (int i = 1; i<=N; i++) { scanf("%d%d%d",&y1,&y2,&x); E[i].y1 = y1; E[i].y2 = y2; E[i].x = x; E[i].id = i; max_y = max(max_y,y2); } sort(E+1,E+N+1,cmp); int ans = 0; for (int i = 1;i<=N;i++) { solve(1,0,2 * max_y,E[i].y1 * 2,E[i].y2 * 2,E[i].id); } for (int i = 1; i<=N; i++) for (int j = i+1; j<=N; j++) if (ok[i][j]) for (int k = j+1;k<=N; k++) { if (ok[i][j]&&ok[i][k]&&ok[j][k]) ans++; } cout <<ans<<endl; }}
0 0
- POJ 1436 - Horizontally Visible Segments
- POJ 1436 - Horizontally Visible Segments
- POJ 1436 Horizontally Visible Segments
- poj 1436 Horizontally Visible Segments
- POJ 1436 Horizontally Visible Segments
- POJ - 1436 Horizontally Visible Segments
- POJ 1436 Horizontally Visible Segments
- poj 1436 Horizontally Visible Segments
- POJ-1436 Horizontally Visible Segments
- POJ 1436 Horizontally Visible Segments
- POJ 1436 Horizontally Visible Segments
- POJ-1436Horizontally Visible Segments
- poj 1436 Horizontally Visible Segments
- zoj 1391 || poj 1436 Horizontally Visible Segments
- POJ 1436 Horizontally Visible Segments 线段树
- POJ 1436 Horizontally Visible Segments 线段树
- poj 1436 Horizontally Visible Segments[线段树]
- poj 1436 线段树 Horizontally Visible Segments
- jdbc连接数据库
- 轻舟已过万重山——真正的技术派公司是怎么联调、测试和发布的?
- 通过 IDEA 去 Debug Jar包
- Django使用nginx部署
- React Native之React速学教程(上)
- POJ-1436Horizontally Visible Segments
- SSH(struts+spring+hibernate)框架搭建流程
- Centos7安装并配置mysql5.6
- VS2010中创建C#的位图(BitMap)的方法与步骤
- Mac Virtualbox Centos Httpd部署安装
- Convert Sorted Array to Binary Search Tree问题及解法
- Codeforces Beta Round #37 B. Computer Game 暴力 贪心
- Android 屏幕密度等级
- 什么是协作?什么是用例实现?