Blocked Billboard B

题目描述

During long milking sessions, Bessie the cow likes to stare out the window of her barn at two huge rectangular billboards across the street advertising "Farmer Alex's Amazingly Appetizing Alfalfa" and "Farmer Greg's Great Grain". Pictures of these two cow feed products on the billboards look much tastier to Bessie than the grass from her farm.

One day, as Bessie is staring out the window, she is alarmed to see a huge rectangular truck parking across the street. The side of the truck has an advertisement for "Farmer Smith's Superb Steaks", which Bessie doesn't quite understand, but she is mostly concerned about the truck potentially blocking the view of her two favorite billboards.

Given the locations of the two billboards and the location of the truck, please calculate the total combined area of both billboards that is still visible. It is possible that the truck obscures neither, both, or only one of the billboards.

在平面直角坐标系中,有两个矩形(保证不相交),然后给出第三个矩形,求这两个矩形没有被第三个矩形遮住的部分的面积。

输入格式

The first line of input contains four space-separated integers: x1 y1 x2 y2, where (x1,y1) and (x2,y2) are the coordinates of the lower-left and upper-right corners of the first billboard in Bessie's 2D field of view. The next line contains four more integers, similarly specifying the lower-left and upper-right corners of the second billboard. The third and final line of input contains four integers specifying the lower-left and upper-right corners of the truck. All coordinates are in the range -1000 to +1000. The two billboards are guaranteed not to have any positive area of overlap between themselves.

题目给出三个坐标,分别表示三个矩形的左下、右上坐标

输出格式

Please output the total combined area of both billboards that remains visible.

输入输出样例

输入 #1

1 2 3 5
6 0 10 4
2 1 8 3

输出 #1

17

说明/提示

Here, 5 units of area from the first billboard and 12 units of area from the second billboard remain visible.

本题因范围是从-1000到1000,所以,我的循环是从+1001开始。

x[][]是指每个点出现的个数,本题是先把前两次出现的个数算出,第三次在把出现次数为1(说明被遮住)的个数减掉。

代码如下:

#include<bits/stdc++.h>
using namespace std;
int x[2202][2202]={},s=0;
int main(){
	for(int k=1;k<=3;k++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		for(int i=a+1001;i<c+1001;i++){
			for(int j=b+1001;j<d+1001;j++){
				if(k<3){
					s++;
					x[i][j]++;
				}
				if(x[i][j]==1&&k==3) s--;
			}
		}
	}
	cout<<s;
	return 0;
}
  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值