Description
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!
水题不解释
#include<stdio.h>
struct point
{
double x1,y1,x2,y2;
};
double det(double ax,double ay,double bx,double by,double cx,double cy)
{
return (bx-ax)*(cy-ay)-(cx-ax)*(by-ay);
}
int judge(point a,point b)
{
if(det(a.x1,a.y1,a.x2,a.y2,b.x1,b.y1)*det(a.x1,a.y1,a.x2,a.y2,b.x2,b.y2)<0)
{
return 1;
}
return 0;
}
int main()
{
int n,i,j;
point a[10000];
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%lf%lf%lf%lf",&a[i].x1,&a[i].y1,&a[i].x2,&a[i].y2);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(judge(a[i],a[j]))
{
printf("burned!\n");
goto end;
}
}
}
printf("ok!\n");
end:;
}
return 0;
}
本文介绍了一种用于电路板路径交叉检测的算法,通过输入电路图,判断是否存在交叉路径,若存在则输出burned!,否则输出ok!。
169

被折叠的 条评论
为什么被折叠?



