C. White Sheet

Posted qq136155330

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C. White Sheet相关的知识,希望对你有一定的参考价值。

C. White Sheet
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1), and the top right — (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), and the top right — (x4,y4). Coordinates of the bottom left corner of the second black sheet are (x5,y5), and the top right — (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,y2 (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,y4 (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,y6 (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
inputCopy
2 2 4 4
1 1 3 5
3 1 5 5
outputCopy
NO
inputCopy
3 3 7 5
0 0 4 6
0 0 7 4
outputCopy
YES
inputCopy
5 2 10 5
3 1 7 6
8 1 11 7
outputCopy
YES
inputCopy
0 0 1000000 1000000
0 0 499999 1000000
500000 0 1000000 1000000
outputCopy
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) lies not strictly inside the white sheet and lies strictly outside of both black sheets.

[思路]:先判断黑一与白的面积的交集,黑一与白的面积的交集,然后算出黑一与白的矩形与黑二与白的矩形的交集
把黑一与白的面积的交集 + 黑一与白的面积的交集 -  黑一与白的矩形与黑二与白的矩形的交集


 [附上代码]:
#include <bits/stdc++.h>
using namespace std;
struct NODE
    int x1, y1, x2, y2;
;
long long judge(NODE a ,NODE b)
    long long x = min(b.x2, a.x2) - max(a.x1, b.x1);
    if(x < 0)
        return -1LL;
    
    long long y = min(b.y2, a.y2) - max(a.y1, b.y1);
    if(y < 0)
        return -1LL;
    
    return x * y;

NODE judge_node(NODE a, NODE b)
    NODE temp;
    temp.x1 = max(a.x1, b.x1);
    temp.y1 = max(a.y1, b.y1);
    temp.x2 = min(a.x2, b.x2);
    temp.y2 = min(a.y2, b.y2);
    return temp;

int main()
    ios::sync_with_stdio(false);
    NODE a, b, c;
    cin >> a.x1 >> a.y1 >> a.x2 >> a.y2;
    cin >> b.x1 >> b.y1 >> b.x2 >> b.y2;
    cin >> c.x1 >> c.y1 >> c.x2 >> c.y2;
    NODE d, e;
    long long s1 = judge(a, b);
    long long s2 = judge(a, c);
    long long s = 0;
    if(s1 > 0)
        s += s1;
    
    if(s2 > 0)
        s += s2;
    
    if(s1 > 0 && s2 > 0)
        d = judge_node(a, c);
        e = judge_node(a, b);
        s -= judge(d, e);
    
    if(s == 1LL * (a.x2 - a.x1) * (a.y2 - a.y1))
        cout << "NO\n";
    
    else
        cout << "YES\n";
    
    return 0;

以上是关于C. White Sheet的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #587 C. White Sheet(思维+计算几何)

简单poi创建execl

streaming.sxssfworkbook和usermodel.workbook有啥区别

php基础:white和 do white区别

使用 TestStack.White 查找 VB6 控件

如何使用 TestStack.White.UIItems 测试 ItemsControl