C. White Sheet
C. White Sheet 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. Input 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 Examples 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,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 << "NOn"; } else{ cout << "YESn"; } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |