• Intersection POJ


    Intersection POJ - 1410

    题目链接:https://vjudge.net/problem/POJ-1410

    题目:

     

     

     题意:判断线段与矩形是否有公共区域。。。一开始我以为判断线段与矩形四条边是否相交就行。。。没想到还有线段在矩形内部也算相交。。。

    // 
    // Created by HJYL on 2020/1/13.
    //
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<cmath>
    #define eps 1e-8
    #define Inf 0x7fffffff
    //#include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+100;
    struct Point{
        double x,y;
    };
    double min(double a, double b) { return a < b ? a : b; }
    
    double max(double a, double b) { return a > b ? a : b; }
    
    bool IsSegmentIntersect(Point a, Point b, Point c, Point d)
    {
        if( min(a.x, b.x) > max(c.x, d.x) ||
            min(a.y, b.y) > max(c.y, d.y) ||
            min(c.x, d.x) > max(a.x, b.x) ||
            min(c.y, d.y) > max(a.y, b.y) )
            return 0;
    
        double h, i, j, k;
    
        h = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
        i = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
        j = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
        k = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
    
        return h * i <= eps && j * k <= eps;
    }
    
    int main()
    {
        int T;
        while(~scanf("%d",&T)) {
            while (T--) {
                Point ju1, ju2, ju3, ju4, gun1, gun2;
                double gunx, guny, gun1x, gun1y, zsx, zsy, yxx, yxy;
                scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &gunx, &guny, &gun1x, &gun1y, &zsx, &zsy, &yxx, &yxy);
                ju1.x = zsx;
                ju1.y = zsy;
                ju2.x = zsx;
                ju2.y = yxy;
                ju3.x = yxx;
                ju3.y = zsy;
                ju4.x = yxx;
                ju4.y = yxy;
                gun1.x = gunx;
                gun1.y = guny;
                gun2.x = gun1x;
                gun2.y = gun1y;
                double a=min(gunx,gun1x);
                double a1=max(gunx,gun1x);
                double b=min(guny,gun1y);
                double b1=max(guny,gun1y);
                double c=min(zsx,yxx);
                double c1=max(zsx,yxx);
                double d=min(zsy,yxy);
                double d1=max(zsy,yxy);
                if (IsSegmentIntersect(gun1, gun2, ju1, ju2) ||
                    IsSegmentIntersect(gun1, gun2, ju1, ju3) ||
                    IsSegmentIntersect(gun1, gun2, ju2, ju4) ||
                    IsSegmentIntersect(gun1, gun2, ju3, ju4) ||
                        (a>=c&&a1<=c1&&b>=d&&b1<=d1)
                    )
                    printf("T
    ");
                else
                    printf("F
    ");
    
            }
        }
        return 0;
    }

     

  • 相关阅读:
    UIWebView 滑动卡停 (卡顿)
    UITapGestureRecognizer 手势传值
    ios8 新特性 UITableViewRowAction
    unrecognized selector sent to instance出现的原因
    iOS 界面上绘制不同字体 颜色 大小的字符串
    NSNumberFormatter 数字格式化输出
    iOS开发-63】Unknown type name "CGRect",did you mean "Rect"?的解决方案
    收起键盘
    iOS8 【xcode6中添加pch全局引用文件】
    fastjson安全漏洞-20200601升级方案
  • 原文地址:https://www.cnblogs.com/Vampire6/p/12198316.html
Copyright © 2020-2023  润新知