zoj 1648 Circuit Board
计算几何线段相交问题,第一次写,所以没有用模版,可以先参考一下这计算几何算法概览
不建议直接套模版,还是先理解一下
过几天将计算几何专题整理一下,再搞模版
/* ***********************************************
Author :xryz
Email :523689985@qq.com
Created Time :3-31 21:09:06
File Name :\Users\xryz\Desktop\CircuitBoard.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{ int i,j,n;
double x1[2024],x2[2024],y1[2024],y2[2024],t1,t2,t3,t4;
bool f;
while(~scanf("%d",&n))
{
for(i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&x1[i],&y1[i],&x2[i],&y2[i]);
f=1;
for(i=0;i<n-1;i++)//判断线段是否分别跨立
{
for(j=i+1;j<n;j++)
{
t1=((x1[i]-x1[j])*(y2[j]-y1[j])-(y1[i]-y1[j])*(x2[j]-x1[j]))*
((x2[j]-x1[j])*(y2[i]-y1[j])-(y2[j]-y1[j])*(x2[i]-x1[j]));
if(t1>0)
{
t2=((x1[j]-x1[i])*(y2[i]-y1[i])-(y1[j]-y1[i])*(x2[i]-x1[i]))*
((x2[i]-x1[i])*(y2[j]-y1[i])-(y2[i]-y1[i])*(x2[j]-x1[i]));
if(t2>0) {f=0;break;}
}
}
if(!f) break;
}
if(f) printf("ok!\n");
else printf("burned!\n");
}
return 0;
}
#include <stdio.h>
struct Point
{
double x,y;
};
Point a[2048],b[2048];
Point operator - (Point m,Point n)
{
Point c;
c.x=m.x-n.x;
c.y=m.y-n.y;
return c;
}
double cross(Point m,Point n)
{
return m.x*n.y-n.x*m.y;
}
int main()
{
int i,j,n;
int flag;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&b[i].x,&b[i].y);
flag=1;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(cross(a[i]-a[j],b[j]-a[j])*cross(b[j]-a[j],b[i]-a[j])>0)
{
if(cross(a[j]-a[i],b[i]-a[i])*cross(b[i]-a[i],b[j]-a[i])>0)
flag=0;
}
if(flag==0) break;
}
if(flag==0) break;
}
if(flag) printf("ok!\n");
else printf("burned!\n");
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/