CCF-CSP 29次 第一题 【202303-1 田地丈量】

  • 首先判断四个顶点是否在区间中,若四个顶点都不在,则无需计算。
  • 否则,以左下角和右上角为基准进行计算。
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int n, a, b;

bool check(int x, int y)
{
	if (x < 0 || x > a || y < 0 || y > b) return true;
	return false;
}

int main()
{
	cin >> n >> a >> b;
	
	int sum = 0;
	
	while (n -- )
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (check(x1, y1) && check(x2, y2) && check(x1, y2) && check(x2, y1)) continue;
		
		x1 = max(0, x1);
		y1 = max(0, y1);
		x2 = min(x2, a);
		y2 = min(y2, b);
		
		sum += (x2 - x1) * (y2 - y1);
	}
	
	cout << sum << endl;
	
	return 0;
}

/*
4 10 10
0 0 5 5
5 -2 15 3
8 8 15 15
-2 10 3 15

44
*/ 

猜你喜欢

转载自blog.csdn.net/qq_51879318/article/details/130187860