• Codeforces 994 C


    C - Two Squares

    思路:

    点积叉积应用

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define fi first
    #define se second
    #define pi acos(-1.0)
    #define LL long long
    #define mp make_pair
    #define pb push_back
    #define ls rt<<1, l, m
    #define rs rt<<1|1, m+1, r
    #define ULL unsigned LL
    #define pll pair<LL, LL>
    #define pii pair<int, int>
    #define piii pair<int,pii>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
    //head
    
    struct P {
        double x, y;
        P(){}
        P(double x, double y):x(x), y(y) {}
        P operator - (P p) {
            return P(x-p.x, y-p.y);
        }
        double cross(P p) {
            return x*p.y - y*p.x;
        }
        double dot(P p) {
            return x*p.x + y*p.y;
        }
    };
    typedef P Vector;
    bool on_seg(P p, Vector a, Vector b) {
        if((a-p).cross(b-p) == 0 && (a-p).dot(b-p) <= 0) return true;
        else return false;
    }
    double area2(Vector a, Vector b, Vector c) {
        return (b-a).cross(c-a);
    }
    bool intersect(Vector a, Vector b, Vector c, Vector d) {
        if(area2(a, c, d) == 0 && area2(b, c, d) == 0 && !on_seg(a, c, d) && !on_seg(b, c, d)
            || area2(a, c, d) * area2(b, c, d) > 0
            || area2(c, a, b) * area2(d, a, b) > 0
        ) return false;
        else return true;
    }
    pii a[4], b[4];
    int main() {
        for (int i = 0; i < 4; i++) scanf("%d %d", &a[i].fi, &a[i].se);
        for (int i = 0; i < 4; i++) scanf("%d %d", &b[i].fi, &b[i].se);
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                Vector aa(a[i].fi, a[i].se);
                Vector bb(a[(i+1)%4].fi, a[(i+1)%4].se);
                Vector c(b[j].fi, b[j].se);
                Vector d(b[(j+1)%4].fi, b[(j+1)%4].se);
                if(intersect(aa, bb, c, d)) return 0*puts("YES");
            }
        }
        for (int i = 0; i < 4; i++) {
            int x = 0, y = 0, xx = 0, yy = 0;
            for (int j = 0; j < 4; j++) {
                Vector A(a[i].fi, a[i].se), B(b[j].fi, b[j].se), C(b[(j+1)%4].fi, b[(j+1)%4].se);
                if(area2(A, B, C) > 0) x++;
                else if(area2(A, B, C) < 0)y++;
                else x++, y++;
                Vector AA(b[i].fi, b[i].se), BB(a[j].fi, a[j].se), CC(a[(j+1)%4].fi, a[(j+1)%4].se);
                if(area2(AA, BB, CC) > 0) xx++;
                else if(area2(AA, BB, CC) < 0) yy++;
                else xx++, yy++;
            }
            if(x == 4 || y == 4 || xx == 4 || yy == 4) return 0*puts("YES");
        }
        puts("NO");
        return 0;
    }
  • 相关阅读:
    JAVA 设计模式 组合模式
    JAVA 设计模式 模板方法模式
    SpringBoot 数据篇之使用JDBC
    [Spring]01_环境配置
    [spring]03_装配Bean
    [Spring]04_最小化Spring XML配置
    [Quartz笔记]玩转定时调度
    [Spring]支持注解的Spring调度器
    asp.net core 系列 13 日志
    asp.net core 系列 12 选项 TOptions
  • 原文地址:https://www.cnblogs.com/widsom/p/9277678.html
Copyright © 2020-2023  润新知