计算几何 线段的各种情况 [好题]
来源:互联网 发布:淘宝女装长袖连衣裙 编辑:程序博客网 时间:2024/05/29 23:47
队内比赛又悲剧了,咱们队各种不在状态啊~ 我悲剧的计算几何就这么悲催咯~ 不过是个好题,可以用来做模板了。线段相交分为几种情况,1不相交,2,重叠,3相交端点在线上,4相交端点不在线上。
为什么还是这么弱啊~~ 和我不想编代码有关系!加油啊~狐狸
#include<stdio.h>#include<cmath>#include<string.h>#define eps 1e-7struct node{ int x,y;};struct segment{ node node1,node2;}line[101];int sign( double x ){ if( fabs(x)<eps ) return 0; else if( x>0 ) return 1; else return -1;}int xmult( node p,node a,node b ){ return sign( (a.x-p.x)*(b.y-p.y) - (b.x-p.x)*(a.y-p.y) );}bool xmultSegment( segment a,segment b ){ if( (xmult( a.node1,a.node2,b.node1 )^xmult( a.node1,a.node2,b.node2 ))==-2 ) { if( (xmult( b.node1,b.node2,a.node1 )^xmult( b.node1,b.node2,a.node2 ))==-2 ) return true; } return false;}double dist( node p1,node p2 ){ return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}bool examine( node a,node b,node c ){ if( fabs(dist(a,c)+dist(c,b)-dist(a,b))<eps ) return true; return false;}bool SamePoint( node a,node b,node c ){ if( a.x==c.x && a.y==c.y ) return true; if( b.x==c.x && b.y==c.y ) return true; return false;}bool exSame( segment a,segment b ){ int index=0; if( SamePoint( a.node1,a.node2,b.node1 ) ) index++; if( SamePoint( a.node1,a.node2,b.node2 ) ) index++; if( SamePoint( b.node1,b.node2,a.node1 ) ) index++; if( SamePoint( b.node1,b.node2,a.node2 ) ) index++; if( index==0 ) return false; else return true;}int inLine( segment a,segment b ){ int index=0; if( xmult( a.node1,a.node2,b.node1 )==0 && examine( a.node1,a.node2,b.node1 ) ) index++; if( xmult( a.node1,a.node2,b.node2 )==0 && examine( a.node1,a.node2,b.node2 ) ) index++; if( xmult( b.node1,b.node2,a.node1 )==0 && examine( b.node1,b.node2,a.node1 ) ) index++; if( xmult( b.node1,b.node2,a.node2 )==0 && examine( b.node1,b.node2,a.node2 ) ) index++; return index;}int main(){ int T,n; int i,j; scanf( "%d",&T ); while( T-- ) { int ans[5]; memset( ans,0,sizeof(ans) ); scanf( "%d",&n ); for( i=1;i<=n;i++ ) scanf( "%d %d %d %d",&line[i].node1.x,&line[i].node1.y,&line[i].node2.x,&line[i].node2.y ); for( i=1;i<=n;i++ ) for( j=i+1;j<=n;j++ ) { if( xmultSegment( line[i],line[j] ) || inLine( line[i],line[j] ) ) { if( inLine( line[i],line[j] )>=2 && !exSame( line[i],line[j] ) ) ans[2]++; else if( inLine( line[i],line[j] )>=1 ) ans[3]++; else ans[4]++; } else ans[1]++; } printf( "%d\n%d\n%d\n%d\n\n",ans[1],ans[2],ans[3],ans[4] ); } return 0;}
- 计算几何 线段的各种情况 [好题]
- POJ 2826 几何/两条线段的各种情况。。
- Rotational Painting hdu 好的计算几何题!!
- 计算几何——线段的性质
- 计算几何-线段
- 【计算几何】线段相交
- 两条线段相交的各种情况
- POJ 计算几何好题推荐
- 计算几何札记-线段交
- poj1039(计算几何)线段相交
- 【计算几何】判断线段相交
- 计算几何 线段相交 模板
- 计算几何的直线、线段的相交判断
- POJ 3304 Segments 【计算几何】【直线和线段的关系】
- HDU 4643 GSM(计算几何求线段的中垂线)
- POJ3304 Segments(计算几何,线段和直线的交点)
- BUPT final C题: 线段相交 -计算几何
- poj 4048 计算几何(线段相交)金华邀请赛 E题
- 回顾习题5(11-09-08)
- 调用约定(pascal,fastcall,stdcall,thiscall,cdecl)区别等
- 嵌入式Linux学习3——vi文本编译器应用
- BMP文件格式详解(BMP file format)
- 编译器GCC使用
- 计算几何 线段的各种情况 [好题]
- 嵌入式Linux学习5——Shell编程
- NeHe OpenGL教程 第三课 添加颜色
- 嵌入式根文件系统制作
- 【总结】2-SAT
- The Simplest View Controller
- 语言表达能力必须的, 文学必须的
- 不用去电影院 3D电影格式/播放全攻略
- http://download.csdn.net/download/dev_eric_cf/2818797