HDU 1086 You can Solve a Geometry Problem too HDU 1147 Pick-up sticks
2012-08-15 21:16
260 查看
这两道题都是规范相交的模板题。
HDU 1086
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1086
View Code
计算几何的参考资料/content/4005332.html
HDU 1086
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1086
View Code
#include<stdio.h> #include<stdlib.h> #include<string.h> struct node { double x,y; }start[200010],end[200010]; double judge(node p1,node p2,node p)//判断点是否在直线的两边 { return ((p1.x-p.x)*(p2.y-p.y)-(p2.x-p.x)*(p1.y-p.y)); } /*inline bool on_megment(node p1,node p2,node p)//判断端点是不是在直线上 { double max=p1.x>p2.x?p1.x:p2.x;//找出直线的左右端点的范围 double min=p1.x<p2.x?p1.x:p2.x; if( p.x>=min&&p.x<=max ) return true; else return false; }*/ bool megment( node p1,node p2,node q1,node q2 ) { double d1=judge( p1,p2,q1 ); double d2=judge( p1,p2,q2 ); double d3=judge( q1,q2,p1 ); double d4=judge( q1,q2,p2 ); if( d1*d2<0&&d3*d4<0 )return true;//如果都异侧就一定相交 /*if( d1==0&&on_megment( p1,p2,q1 ) ) returntrue;//d为0是平行的情况,这是我们就要考虑是不是端点在直线上 if( d2==0&&on_megment( p1,p2,q2 ) ) returntrue; if( d3==0&&on_megment( q1,q2,p1 ) ) returntrue; if( d4==0&&on_megment( q1,q2,p2 ) ) returntrue;*/ return false; } int main() { int n,hash[100010]; while( scanf( "%d",&n ),n ) { memset( hash, 0,sizeof( hash ) ); int count=0; for( int i=1; i<=n; i++ ) scanf( "%lf%lf%lf%lf",&start[i].x,&start[i].y,&end[i].x,&end[i].y ); for( int i=1;i<=n; i++ ) for( int j=i+1;j<=n; j++ ) { if( megment( start[i],end[i],start[j],end[j] ) ) { hash[i]=1;//记录被覆盖的棍子 count++; break; } } int sum=0; count=n-count; printf( "Top sticks:" ); for( int i=1;i<=n; i++ ) { if( 0==hash[i] ) { sum++; printf( count==sum?" %d.\n":" %d,",i ); } } } return 0; }
计算几何的参考资料/content/4005332.html
相关文章推荐
- HDU 1147 Pick-up sticks
- HDU 1147 Pick-up sticks(线段是否相交)
- HDU 1147 Pick-up sticks(计算几何 判断直线相交)
- HDU-1147-Pick-up sticks
- POJ 2653 && HDU 1147 Pick-up sticks(计算几何)
- hdu 1147 Pick-up sticks(求是否有交点)
- hdu_1147 Pick_up sticks
- HDU 1147 Pick-up sticks(简单的线段相交)
- hdu 1147【Pick-up sticks】
- hdu 1147 Pick-up sticks
- hdu_1147 Pick-up sticks(线段相交)
- HDU 1147 Pick-up sticks
- HDU 1147 Pick-up sticks 线段判交。暴搜
- hdu 1147 Pick-up sticks(线段相交+枚举)
- hdu-1147 Pick-up sticks(判断线段相交)
- hdu 1147 Pick-up sticks 向量积求线段相交
- HDU 1147 Pick-up sticks (叉乘判断线段相交)
- hdu 1147:Pick-up sticks(基本题,判断两线段相交)
- HDU 1147 Pick-up sticks(线段相交)
- hdu 1147 Pick-up sticks 判断线段相交 ~~ 注意判断顺序!!不然容易超时