矩形(并查集)
来源:互联网 发布:照片mv制作软件 编辑:程序博客网 时间:2024/05/15 02:06
题意:
• 在平面上画了N个长方形,每个长方形的边平行于坐标轴并且顶点坐标为整数。我们用以下方式定义印版:
– 每个长方形是一个印版;
– 如果两个印版有公共的边或内部,那么它们组成新的印版,否则这些印版是分离的
就是把两个相交的矩形变成一个
思路:
判断他们是否是相交,是的话就用并查集放到一个集合里面去,然后看被分成几个集合就好了
const maxn=10000;var f,x1,y1,x2,y2,t:array [1..maxn] of longint; i,j,n,ans:longint;function father(x:longint):longint;var i,j:longint;begin if x<>f[x] then father:=father(f[x]) else father:=x; f[x]:=father;end;function cheak(i,j:longint):boolean;begin if (x1[i]>x2[j]) or (x2[i]<x1[j]) then exit(false); if (y1[i]>y2[j]) or (y2[i]<y1[j]) then exit(false); if (x2[i]=x1[j]) and (y1[i]=y2[j]) then exit(false); if (x1[i]=x2[j]) and (y2[i]=y1[j]) then exit(false); if (x2[i]=x1[j]) and (y2[i]=y1[j]) then exit(false); if (x1[i]=x2[j]) and (y1[i]=y2[j]) then exit(false); exit(true);end;begin readln(n); for i:=1 to n do readln(x1[i],y1[i],x2[i],y2[i]); for i:=1 to n do f[i]:=i; for i:=1 to n do for j:=i+1 to n do if cheak(i,j) then f[father(i)]:=father(j); for i:=1 to n do if father(f[i])<>0 then inc(t[father(f[i])]); for i:=1 to 10000 do if t[i]<>0 then inc(ans); writeln(ans);end.
0 0
- 矩形(并查集)
- SSL1222 矩形(并查集)
- SDNU 1016.矩形合并 并查集
- 并查集(集并查)
- Hrbust 1619 只有矩形【逆序思维+枚举+并查集优化】
- 并查集(含关系并查集)
- 【并查集】食物链(关系并查集)
- 【并查集】并查集详解(转)
- 分组并查集(种类并查集)
- 并查集, 畅通工程(简单并查集)
- [数据结构]并查集水体POJ2236(并查集)
- 并查集(disjoint_set)
- 并查集(模板)
- 并查集(亲戚)
- POJ2524(并查集)
- POJ_2236(并查集)
- poj2492(并查集)
- HDU1272(并查集)
- 正则表达式实例运用
- Json(jackson)中通用的存放和获取List列表方法
- iOS 画图对号
- 单元测试军规:如何编写更好的单元测试
- oracle学习之:使用logmnr工具挖掘日志
- 矩形(并查集)
- sublime 配置node 环境
- java 继承常见的面试题
- cocoapods使用2
- SQL 问题记录
- C++从零实现深度神经网络之零——前言
- 网络相关协议要点
- Unity3D的资源管理
- python异步