zoukankan      html  css  js  c++  java
  • White Sheet (矩形面积模板) (Codeforces Round #587 (Div. 3) )

    There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0)(0,0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1)(x1,y1), and the top right — (x2,y2)(x2,y2).

    After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x3,y3)(x3,y3), and the top right — (x4,y4)(x4,y4). Coordinates of the bottom left corner of the second black sheet are (x5,y5)(x5,y5), and the top right — (x6,y6)(x6,y6).

    Example of three rectangles.

    Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets.

    Input

    The first line of the input contains four integers x1,y1,x2,y2x1,y1,x2,y2 (0x1<x2106,0y1<y2106)(0≤x1<x2≤106,0≤y1<y2≤106) — coordinates of the bottom left and the top right corners of the white sheet.

    The second line of the input contains four integers x3,y3,x4,y4x3,y3,x4,y4 (0x3<x4106,0y3<y4106)(0≤x3<x4≤106,0≤y3<y4≤106) — coordinates of the bottom left and the top right corners of the first black sheet.

    The third line of the input contains four integers x5,y5,x6,y6x5,y5,x6,y6 (0x5<x6106,0y5<y6106)(0≤x5<x6≤106,0≤y5<y6≤106) — coordinates of the bottom left and the top right corners of the second black sheet.

    The sides of each sheet of paper are parallel (perpendicular) to the coordinate axes.

    Output

    If some part of the white sheet can be seen from the above after the two black sheets are placed, print "YES" (without quotes). Otherwise print "NO".

    Examples
    input
    Copy
    2 2 4 4
    1 1 3 5
    3 1 5 5
    
    output
    Copy
    NO
    
    input
    Copy
    3 3 7 5
    0 0 4 6
    0 0 7 4
    
    output
    Copy
    YES
    
    input
    Copy
    5 2 10 5
    3 1 7 6
    8 1 11 7
    
    output
    Copy
    YES
    
    input
    Copy
    0 0 1000000 1000000
    0 0 499999 1000000
    500000 0 1000000 1000000
    
    output
    Copy
    YES
    
    Note

    In the first example the white sheet is fully covered by black sheets.

    In the second example the part of the white sheet can be seen after two black sheets are placed. For example, the point (6.5,4.5)(6.5,4.5) lies not strictly inside the white sheet and lies strictly outside of both black sheets.

     

     

    #include <iostream>
    #include <vector>
    using namespace std;
    using ll = long long;
    const ll MOD = 1e9 + 7;
     
    struct Rect {
        ll x1, y1, x2, y2;
     
        ll area() const {
            if (x2 < x1 || y2 < y1) return 0;
            else return (x2 - x1) * (y2 - y1);
        }
    };
    Rect its(Rect a, Rect b) {
        Rect res;
        res.x1 = max(a.x1, b.x1);
        res.x2 = min(a.x2, b.x2);
        res.y1 = max(a.y1, b.y1);
        res.y2 = min(a.y2, b.y2);
        return res;
    }
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
     
        Rect w, b1, b2;
        cin >> w.x1 >> w.y1 >> w.x2 >> w.y2;
        cin >> b1.x1 >> b1.y1 >> b1.x2 >> b1.y2;
        cin >> b2.x1 >> b2.y1 >> b2.x2 >> b2.y2;
     
        ll res = w.area() - its(w, b1).area() - its(w, b2).area() + its(w, its(b1, b2)).area();
        if (res > 0) cout << "YES
    ";
        else cout << "NO
    ";
    }
    所遇皆星河
  • 相关阅读:
    Linux之mysql的重新安装
    prometheus监控采集数据promSql
    安装grafana
    prometheus server主配置文件prometheus.yml
    【Java拾遗】不可不知的 Java 序列化
    Centos7 openssh 离线升级8.4
    web for pentester sqli
    web for pentester xss
    ESXI 安装脚本
    nginx 499状态码排查
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11565825.html
Copyright © 2011-2022 走看看