标签:
2 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.00 3 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.000 0.00 0.00 1.00 0.00 0
1 3
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double esp=1e-7;
struct point{
double x,y;
}p[110],q[110];
double cross(point a,point b,point c){
return (c.x-a.x)*(c.y-b.y)-(c.x-b.x)*(c.y-a.y);
}
bool insert(point aa,point bb,point cc,point dd){
if(max(aa.x,bb.x)<min(cc.x,dd.x)) return false;
if(max(aa.y,bb.y)<min(cc.y,dd.y)) return false;
if(max(cc.x,dd.x)<min(aa.x,bb.x)) return false;
if(max(cc.y,dd.y)<min(aa.y,bb.y)) return false;
if(cross(aa,bb,cc)*cross(aa,bb,dd)>0) return false;
if(cross(cc,dd,aa)*cross(cc,dd,bb)>0) return false;
return true;
}
int main(){
int n;
while(~scanf("%d",&n),n){
int i,j;
double s1,s2;
for(i=1;i<=n;++i){
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&q[i].x,&q[i].y);
}
int ncase=0;
for(i=1;i<=n;++i){
for(j=i+1;j<=n;++j){
if(insert(p[i],q[i],p[j],q[j])) ncase++;
}
}
printf("%d\n",ncase);
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
hdoj-1086-You can Solve a Geometry Problem too 判断线段是否相交
标签:
原文地址:http://blog.csdn.net/qq_18062811/article/details/46972393