Segment set(普通并查集+计算几何两线段相交与否)
来源:互联网 发布:手机淘宝联盟能推广吗 编辑:程序博客网 时间:2024/06/05 03:25
hdu1558 判断两线段相不相交贴的模板,暂时没搞懂
#include <iostream>#include <stdio.h>#include <math.h>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <string>#include <string.h>#include <map>#include <set>using namespace std;int f[1001];typedef struct point{ double x; double y;}Point;//判断直线AB是否与线段CD相交bool lineIntersectSide(Point A, Point B, Point C, Point D){ // A(x1, y1), B(x2, y2)的直线方程为: // f(x, y) = (y - y1) * (x1 - x2) - (x - x1) * (y1 - y2) = 0 double fC = (C.y - A.y) * (A.x - B.x) - (C.x - A.x) * (A.y - B.y); double fD = (D.y - A.y) * (A.x - B.x) - (D.x - A.x) * (A.y - B.y); if(fC * fD > 0) return false; return true;}bool sideIntersectSide(Point A, Point B, Point C, Point D){ if(!lineIntersectSide(A, B, C, D)) return false; if(!lineIntersectSide(C, D, A, B)) return false; return true;}struct line{ double x1,y1,x2,y2;};line l[1005];int findfa(int x){ if(x==f[x]) { return x; } else { return f[x]=findfa(f[x]); }}int main(){ int t,i,m,k,id,ans; char s[2]; double x1,y1,x2,y2; scanf("%d",&t); int o=1; while(t--) { if(o!=1) printf("\n"); scanf("%d",&m); for(i=1;i<=1000;i++) f[i]=i; id=1; while(m--) { scanf("%s",s); if(s[0]=='P') { scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); l[id].x1=x1;l[id].x2=x2;l[id].y1=y1;l[id].y2=y2; for(i=1;i<=id-1;i++) { point A={l[id].x1,l[id].y1}; point B={l[id].x2,l[id].y2}; point C={l[i].x1,l[i].y1}; point D={l[i].x2,l[i].y2}; if(sideIntersectSide(A,B,C,D)) { // cout<<"id:"<<id<<" "; int tx=findfa(i),ty=findfa(id); if(tx!=ty) f[ty]=tx; } } id++; } else { scanf("%d",&k); ans=0; for(i=1;i<=id;i++) { int t=findfa(i); } for(i=1;i<=id;i++) { if(f[k]==f[i])ans++; } printf("%d\n",ans); } } o++; } return 0;}
0 0
- Segment set(普通并查集+计算几何两线段相交与否)
- hdu 1558 Segment set(并查集+计算几何线段相交)
- 【计算几何初步-线段相交+并查集】【HDU1558】Segment set
- HDU 1158 Segment set(线段相交 并查集)
- hdu1558 Segment set (判断线段相交+并查集)
- Segment set(并查集 + 计算几何问题)
- POJ 1127 基础计算几何(判断两线段相交)+并查集
- HDU 1558 Segment set (并查集+线段相交)
- hdu 1558 Segment set(并查集+线段相交)
- hdu 1558 Segment set 线段相交+并查集
- [HDOJ 1558] Segment set [线段相交+并查集]
- HDU 1558 Segment set(线段相交+并查集)
- HDU 1558 Segment set(判断线段相交+并查集)
- hdu 1558 Segment set(线段相交+并查集)
- HDU1558 - Segment set 并查集 + 判断线段相交
- HDU 1558 Segment set 并查集 线段相交
- HDU-1558,Segment set,并查集+线段相交模拟
- HDU 1558 Segment set, 计算几何+并查集
- 用WINRAR将.bat文件转为自启动
- 欢迎使用CSDN-markdown编辑器
- i2c_register_board_info没有EXPORT_SYMBOL_GPL导出的解决方法
- Could not find resource FancyMapper.xml
- Caused by: java.lang.NoSuchFieldError: TRACE
- Segment set(普通并查集+计算几何两线段相交与否)
- 1415: [Noi2005]聪聪和可可(BFS+SPFA+概率DP)
- 数字证书及CA的扫盲介绍
- 如何修改JMeter 界面语言
- 用字体在网页中画icon图标
- 观看maven视频记录
- 在windows操作系统中使用linux
- ArrayAdapter<T>,Filter实现列表搜索
- Python GUI编程各种实现的对比