ZOJ 1648:Circuit Board __判断两线段相交
2012-08-06 14:05
369 查看
On the circuit board, there are lots of circuit paths. We know the basic constrain is that no two path cross each other, for otherwise the board will be burned.
Now given a circuit diagram, your task is to lookup if there are some crossed paths. If not find, print "ok!", otherwise "burned!" in one line.
A circuit path is defined as a line segment on a plane with two endpoints p1(x1,y1) and p2(x2,y2).
You may assume that no two paths will cross each other at any of their endpoints.
Input
The input consists of several test cases. For each case, the first line contains an integer n(<=2000), the number of paths, then followed by n lines each with four float numbers x1, y1, x2, y2.
Output
If there are two paths crossing each other, output "burned!" in one line; otherwise output "ok!" in one line.
Sample Input
1
0 0 1 1
2
0 0 1 1
0 1 1 0
Sample Output
ok!
burned!
//话说计算几何模板好多。需要明白嵌套。
Now given a circuit diagram, your task is to lookup if there are some crossed paths. If not find, print "ok!", otherwise "burned!" in one line.
A circuit path is defined as a line segment on a plane with two endpoints p1(x1,y1) and p2(x2,y2).
You may assume that no two paths will cross each other at any of their endpoints.
Input
The input consists of several test cases. For each case, the first line contains an integer n(<=2000), the number of paths, then followed by n lines each with four float numbers x1, y1, x2, y2.
Output
If there are two paths crossing each other, output "burned!" in one line; otherwise output "ok!" in one line.
Sample Input
1
0 0 1 1
2
0 0 1 1
0 1 1 0
Sample Output
ok!
burned!
//话说计算几何模板好多。需要明白嵌套。
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<queue> #include<stack> #include<map> #include<vector> #include<algorithm> using namespace std; #define maxn 2005 #define min(x,y) (x<y?x:y) #define max(x,y) (x>y?x:y) struct point { double x,y; }; struct line { point sp,ep; }; line a[maxn]; double x_multi(point p1,point p2,point p3) //叉积 { return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y); } bool Onsegment(point p1,point p2,point p3) //快速排斥实验 { double min_x=min(p1.x,p2.x); double min_y=min(p1.y,p2.y); double max_x=max(p1.x,p2.x); double max_y=max(p1.y,p2.y); if(p3.x>=min_x&&p3.x<=max_x&&p3.y>=min_y&&p3.y<=max_y) return true; return false; } bool Is_intersected(point p1,point p2,point p3,point p4) { double d1=x_multi(p1,p2,p3); double d2=x_multi(p1,p2,p4); double d3=x_multi(p3,p4,p1); double d4=x_multi(p3,p4,p2); if(d1*d2<0.0&&d3*d4<0.0) return true; if(d1==0.0&&Onsegment(p1,p2,p3)) //跨立实验 return true; if(d2==0.0&&Onsegment(p1,p2,p4)) return true; if(d3==0.0&&Onsegment(p3,p4,p1)) return true; if(d4==0.0&&Onsegment(p3,p4,p2)) return true; return false; } int main() { int n,i,j; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%lf%lf%lf%lf",&a[i].sp.x,&a[i].sp.y,&a[i].ep.x,&a[i].ep.y); for(i=0;i<n;i++) for(j=i+1;j<n;j++) { if(Is_intersected(a[i].sp,a[i].ep,a[j].sp,a[j].ep)) { puts("burned!"); goto end; } } puts("ok!"); end:; } return 0; }
相关文章推荐
- ZOJ 1648 Circuit Board【跨立实验判断线段相交】
- zoj 1648 Circuit Board (判断线段是否相交)
- ZOJ 1648 Circuit Board(判断线段相交)
- ZOJ 1648 Circuit Board(线段相交判定 刘汝佳模板)
- ZOJ1648 Circuit Board(线段相交)
- zoj 1648 判断线段是否相交
- Circuit Board(zju1648,判断线段相交)
- ZOJ 1648 Circuit Board(线段相交判定)
- ZOJ--1648:Circuit Board(跨立实验线段判交)
- zoj 1721 判断2条线段(完全)相交
- zoj 1010 (线段相交判断+多边形求面积)
- zoj 1010 Area 判断线段是否相交(把线段扩充一倍后 好处理) + 多边形求面积
- zoj 1158 判断2线段完全相交
- Circuit Board(判断线段相交)
- zju1648 判断两条线段是否相交
- ZOJ 1648 线段相交
- 【计算几何】判断线段相交
- HDU 1086 You can Solve a Geometry Problem too(判断线段相交)
- 计算几何之判断两线段是否相交
- 判断两条线段是否相交