其他分享
首页 > 其他分享> > Codeforces Round #587 White Sheet(几何覆盖)

Codeforces Round #587 White Sheet(几何覆盖)

作者:互联网

White Sheet

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).

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

input

2 2 4 4
1 1 3 5
3 1 5 5

output

NO

链接:https://codeforces.com/contest/1216/problem/C

题意:黑四边形将白四边形覆盖,问是否可以看到白四边形。

题解:Ares=(S1与S2重合面积+S1与S3重合面积)-(S2与S3重合面积)与S1重合面积,然后Ares与S1面积比较。

#include<iostream>
using namespace std;
long long query(long long x1,long long y1,long long x2,long long y2,long long x3,long long y3,long long x4,long long y4)
{
	long long x5=max(x1,x3);
	long long y5=max(y1,y3);
	long long x6=min(x2,x4);
	long long y6=min(y2,y4);
	if(x5>x6||y5>y6)
	return 0;
	return abs((x6-x5)*(y6-y5));
}
int main()
{
	long long x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
	scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2);
	scanf("%I64d%I64d%I64d%I64d",&x3,&y3,&x4,&y4);
	scanf("%I64d%I64d%I64d%I64d",&x5,&y5,&x6,&y6);
	long long s1=(x2-x1)*(y2-y1);//s1
	long long s12=query(x1,y1,x2,y2,x3,y3,x4,y4);//s1&&s2
	long long s13=query(x1,y1,x2,y2,x5,y5,x6,y6);//s1&&s3
	long long x231=max(x3,x5);
	long long y231=max(y3,y5);
	long long x232=min(x4,x6);
	long long y232=min(y4,y6);
	long long s123=query(x1,y1,x2,y2,x231,y231,x232,y232);//s1&&s2&&s3
	if(s1-(s12+s13-s123)>0)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

 

标签:587,y2,Sheet,Codeforces,long,x2,y1,sheet,x1
来源: https://blog.csdn.net/qq_43381887/article/details/101165751