题目描述

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.

Problem credits: Brian Dean

思路:模拟即可。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct nond{ int x1,y1,x2,y2; };
int area(nond r){
return (r.x2-r.x1)*(r.y2-r.y1);
}
int intersect_area(nond p,nond q){
int x_overlap=max(,min(p.x2,q.x2)-max(p.x1,q.x1));
int y_overlap=max(,min(p.y2,q.y2)-max(p.y1,q.y1));
return x_overlap*y_overlap;
}
int main(){
nond a,b,t;
cin>>a.x1>>a.y1>>a.x2>>a.y2;
cin>>b.x1>>b.y1>>b.x2>>b.y2;
cin>>t.x1>>t.y1>>t.x2>>t.y2;
cout<<area(a)+area(b)-intersect_area(a,t)-intersect_area(b,t);
}

最新文章

  1. python基础-生成随机字符串方法
  2. LNMP(linux+nginx+mysql+php)服务器环境配置
  3. Servlet+JSP+JavaBean开发模式(MVC)介绍
  4. Ha ha lou!
  5. html禁止清除input文本输入缓存
  6. ios6-7以后用户开热点后的屏幕适配
  7. Java设计模式之装饰模式趣谈
  8. tar、zip 、unzip 打包与压缩 (参考:http://pengyl.blog.51cto.com/5591604/1191197)
  9. win7系统中桌面图标显示不正常问题
  10. System.Web Namespce
  11. “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX
  12. PHP操作Mysql中间BLOB场
  13. 深入理解计算机系统chapter1
  14. poj 3278 简单BFS
  15. nginx部署~dotnetCore+mvc网站502
  16. BP神经网络(原理及MATLAB实现)
  17. Linux下安装gradle
  18. 【dp】P1434 [SHOI2002]滑雪
  19. 复用微信小程序源码包后仍然有原小程序的版本管理怎么处理
  20. SAP SQVI 快速浏览器

热门文章

  1. A. Train and Peter
  2. bzoj1433[ZJOI2009]假期的宿舍(匈牙利)
  3. django 菜单权限
  4. Java编程思想读书笔记_第二章
  5. Java学习笔记_网络+多线程
  6. 在Django中使用redis:包括安装、配置、启动。
  7. Android开发高手课笔记 - 01 崩溃优化(上):关于“崩溃”那点事
  8. 简单TCP代码
  9. [Windows Server 2008] ASP.net安装方法
  10. 【译】x86程序员手册07 - 2.5操作数选择