| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我的想法,比较简单点 大家可以看看//我从反面考虑,将不相交的情况列举出来
#include <stdio.h>
int main()
{
int x1,y1,x2,y2,xl,yt,xr,yb,i,n,a,b,c,f1,f2,f3,f4,temp;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&xl,&yt,&xr,&yb);
if(xl>xr)
{
temp=xl;
xl=xr;
xr=temp;
}
if(yt<yb)
{
temp=yt;
yt=yb;
yb=temp;
}
a=y1-y2;
b=x2-x1;
c=x1*y2-y1*x2;
f1=a*xl+b*yb+c;
f2=a*xl+b*yt+c;
f3=a*xr+b*yb+c;
f4=a*xr+b*yt+c;
if(f1>0&&f2>0&&f3>0&&f4>0||f1<0&&f2<0&&f3<0&&f4<0) //判断线段所在直线是否与矩形相交
printf("F\n");
else if((x1>xr&&x2>xr)||(x1<xl&&x2<xl))//若线段所在直线与矩形相交,则满足一下两种情况的时候线段不与矩形相交
printf("F\n");
else if((y1>yt&&y2>yt)||(y1<yb&&y2<yb))
printf("F\n");
else
printf("T\n");
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator