Circuit Board(zju1648,判断线段相交)
2013-08-22 21:47
337 查看
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1648
Circuit Board
Time Limit: 2 Seconds Memory Limit: 65536 KB
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!
解析:
题意:给出n条线段,判断是否存在线段相交
思路:
判断是否存在两线段相交,在于判断是否相互跨立
248 KB 120 ms C++ (g++ 4.4.5) 1112 B
*/
Circuit Board
Time Limit: 2 Seconds Memory Limit: 65536 KB
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!
解析:
题意:给出n条线段,判断是否存在线段相交
思路:
判断是否存在两线段相交,在于判断是否相互跨立
248 KB 120 ms C++ (g++ 4.4.5) 1112 B
*/
#include<stdio.h> #include<string.h> #include<math.h> #include <iostream> using namespace std; const int maxn=2000+10; struct point { double x; double y; }p1[maxn],p2[maxn]; double Cross(point A,point B) { return A.x*B.y-A.y*B.x; } point sub(point a,point b) { point c; c.x=a.x-b.x; c.y=a.y-b.y; return c; } bool Intersect(point p1,point p2,point Q1,point Q2) { point v1=sub(p1,Q1); point v2=sub(Q2,Q1); point v3=sub(p2,Q1); point v4=sub(p2,p1); point v5=sub(Q2,p1); point v6=sub(Q1,p1); if(Cross(v1,v2)*Cross(v2,v3)>0&&Cross(v6,v4)*Cross(v4,v5)>0)//相互跨立,这里的相交不包含端点相交 return 1; else return 0; } int main() {int n,i,j; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { scanf("%lf%lf%lf%lf",&p1[i].x,&p1[i].y,&p2[i].x,&p2[i].y); } if(n==1) {printf("ok!\n"); continue; } int ok=1; for(i=0;i<n;i++) { if(!ok) break; for(j=i+1;j<n;j++) { if(Intersect(p1[i],p2[i],p1[j],p2[j])) {ok=0; break; } } } if(ok) printf("ok!\n"); else printf("burned!\n"); } return 0; }
相关文章推荐
- ZOJ 1648 Circuit Board(判断线段相交)
- zoj 1648 Circuit Board (判断线段是否相交)
- ZOJ 1648 Circuit Board【跨立实验判断线段相交】
- ZOJ 1648:Circuit Board __判断两线段相交
- zju1648 判断两条线段是否相交
- zoj 1648 判断线段是否相交
- ZOJ1648 Circuit Board(线段相交)
- ZOJ 1648 Circuit Board(线段相交判定)
- Circuit Board(判断线段相交)
- ZOJ 1648 Circuit Board(线段相交判定 刘汝佳模板)
- POJ 2653 Pick-up sticks 枚举 + 判断两线段规范相交
- 判断两条线段是否相交_模版
- pku 1556 The Doors 计算几何 之 叉积判断线段是否相交
- 判断任意多边形与矩形的相交(线段与矩形相交或线段与线段相交)
- 判断两条线段相交的算法
- HLG 1507 水神的栅栏【判断线段相交+并查集】
- 计算几何基础——矢量和叉积 && 叉积、线段相交判断、凸包(转载)
- 判断线段相交并求交点
- Intersecting Lines(判断线段相交)
- POJ 2653 Pick-up sticks(判断线段相交)