POJ 1410 计算几何

思路:

快速排斥实验+跨立实验

注意矩形是实心的,即在内部也算相交。

 

 

 

//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
int cases,xs,ys,xe,ye,xl,yt,xr,yb;
bool chaji(int x1,int y1,int x2,int y2){return x1*y2-x2*y1>=0;}
bool kl(int x1,int y1,int x2,int y2){
    return chaji(xs-x1,ys-y1,x2-x1,y2-y1)!=chaji(xe-x1,ye-y1,x2-x1,y2-y1)
         &&chaji(x1-xs,y1-ys,xe-xs,ye-ys)!=chaji(x2-xs,y2-ys,xe-xs,ye-ys);
}
bool check(int x1,int y1,int x2,int y2){
    int Y1=min(ys,ye),Y2=max(ys,ye);
    int minx=max(x1,xs),maxx=min(x2,xe);
    int miny=max(Y1,y1),maxy=min(Y2,y2);
    return minx<=maxx&&miny<=maxy&&kl(x1,y1,x2,y2);
}
bool ck2(){return xl<=xs&&yb<=ys&&xr>=xe&&yt>=ye;}
signed main(){
    scanf("%d",&cases);
    while(cases--){
        scanf("%d%d%d%d%d%d%d%d",&xs,&ys,&xe,&ye,&xl,&yt,&xr,&yb);
        if(xs>xe)swap(xs,xe),swap(ys,ye);
        if(xl>xr)swap(xl,xr);if(yt<yb)swap(yt,yb);
        if(check(xl,yt,xr,yt)||check(xl,yb,xr,yb)||check(xl,yb,xl,yt)||check(xr,yb,xr,yt)||ck2())puts("T");
        else puts("F");
    }
}

 

posted @ 2018-07-28 14:48  SiriusRen  阅读(122)  评论(0编辑  收藏  举报