poj 1468 Rectangles
来源:互联网 发布:好玩的手游推荐 知乎 编辑:程序博客网 时间:2024/05/22 08:29
题目:给定n个矩形,问有多少个被完全覆盖。
分析:暴力。这道题目想了很久除了暴力想不出更好的方法了,因为数据范围不清楚,只有点的个数,没有点的范围。最后只能利用Dancing_links的链表做优化,利用L,R两个指针数组把排好序的矩形构造成链表,每次找到一个被覆盖的矩形,直接从链表中删除。最后运行时间还是600ms左右,总觉得应该又更好的算法。
说明:在讨论版中看到有人说用树状数组,木有想出来怎么写= =!。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;typedef struct nodep{int minx,miny,maxx,maxy;}point;point P[ 5005 ];int L[ 5005 ];int R[ 5005 ];bool cmp( point a, point b ){if ( a.minx == b.minx ) {if ( a.miny == b.miny ) {if ( a.maxx == b.maxx )return a.maxy < b.maxy;else return a.maxx < b.maxx;}else return a.miny > b.miny;}else return a.minx > b.minx;}int main(){int n;while ( scanf("%d",&n) != EOF ) {for ( int i = 1 ; i <= n ; ++ i )scanf("%d%d%d%d",&P[i].minx,&P[i].maxx,&P[i].miny,&P[i].maxy);sort( P+1, P+n+1, cmp );for ( int i = 0 ; i <= n ; ++ i ) {L[i] = i-1; R[i] = i+1;}int count = 0;for ( int i = 1 ; i <= n ; ++ i ) {for ( int j = R[0] ; j != i ; j = R[j] ) if ( P[i].minx <= P[j].minx && P[i].miny <= P[j].miny && P[i].maxx >= P[j].maxx && P[i].maxy >= P[j].maxy ) {R[L[j]] = R[j];L[R[j]] = L[j];count ++;if ( P[i].minx == P[j].minx && P[i].miny == P[j].miny && P[i].maxx == P[j].maxx && P[i].maxy == P[j].maxy ) {R[L[i]] = R[i];L[R[i]] = L[i];count ++;}}}printf("%d\n",count);}return 0;}
- poj 1468 Rectangles
- poj 1468 Rectangles
- POJ 1468 Rectangles
- POJ 1468 Rectangles 笔记
- zoj 1139 || poj 1468 Rectangles
- poj 1693 Counting Rectangles
- Rectangles POJ 3695
- POJ 1314 Finding Rectangles
- POJ 3695 Rectangles 笔记
- 1468 Rectangles
- POJ 3695 Rectangles(矩形切割)
- POJ 1314 Finding Rectangles 笔记
- Rectangles
- Rectangles
- Rectangles
- Rectangles
- Rectangles
- POJ 1468 Rectangles(判定点在平行坐标轴的矩形内)
- 建置一個 WINCE 下的 XML BASE 的人機介面引擎 ---- 繪圖引擎篇 (2)
- 三维人脸识别研究
- 数据结构图的数组表示法以及深度,广度遍历
- linux/compiler.h 内核内一些关键词的定义
- 国内外搜索引擎的爬虫汇总
- poj 1468 Rectangles
- MINA2.0用户手册中文版--第三章 第二节 IoService接口详情
- robots协议
- 消息驱动Bean(MDB)编写规则
- js鼠标跟随效果
- Eclipse的插件机制
- SPFA算法
- CUDA3--矩阵乘法,利用共享存储器
- php 接口类,抽象类 的实际作用