AcWing 1749 阻挡广告牌 II 题解(春季每日一题)

模拟,但是需要注意的细节比较多, (也可能是我晚上脑子不清醒了…),反正就是题不难,但是要注意细节
AcWing 1749. 阻挡广告牌 II

#include<bits/stdc++.h>

using namespace std;

const int N = 2010;

int x[4], y[4];
int r1, c1;//第一个的长宽 
int r2, c2;//第二个的长宽
int g[N][N];//染色布

int main()
{
	cin>>x[0]>>y[0]>>x[1]>>y[1];  //记录第一个牌,割草机 
	cin>>x[2]>>y[2]>>x[3]>>y[3];  //记录第二个牌,饲料牌 
	r1 = x[1] - x[0];
	c1 = y[1] - y[0];
	r2 = x[3] - x[2];
	c2 = y[3] - y[2];
	
	int s = r1 * c1;  //记录割草机牌子面积 
	int s2 = r2 * c2;
	
	if(x[0] >= x[2] && x[1] <= x[3] && y[0] >= y[2] && y[1] <= y[3]){  //全覆盖 
		cout<<0<<endl;  //全覆盖 
	}	
	else if(x[0] >= x[2] && x[1] <= x[3]){  //横向对齐或覆盖 
		if(y[3] >= y[0] && y[2] <= y[1]){  //有交集 
			if(y[3] <= y[1] && y[2] >= y[0]){  //中覆盖 
				cout<<s<<endl;
			}
			else if(y[3] >= y[1] && y[2] >= y[0]){  //上覆盖 
				int iu = y[1] - y[2];
				cout<<s - iu * (x[1] - x[0]);				
			}
			else{  //下覆盖 
				int iu = y[3] - y[0];
				cout<<s - iu * (x[1] - x[0]);				
			}
		}
		else{
			cout<<s<<endl;  //没有交集 
		}
	}
	else if(y[0] >= y[2] && y[1] <= y[3]){  //纵向对齐或覆盖
		if(x[2] <= x[1] && x[3] >= x[0]){			
			if(x[3] <= x[1] && x[2] >= x[0]){  //中覆盖 
				cout<<s<<endl;
			}
			else if(x[3] <= x[1] && x[2] <= x[0]){  //左覆盖 
			
				int iu = x[3] - x[0];
				cout<<s - iu * (y[1] - y[0]);				
			}
			else{  //右覆盖 
				int iu = x[1] - x[2];
				cout<<s - iu * (y[1] - y[0]);				
			}			
		}
		else{
			cout<<s<<endl;  //没有交集 
		}		 
	} 
	else{
		cout<<s<<endl;
	}
	return 0;
} 
 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值