题目描述

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);
}

洛谷 P2084 进制转换的更多相关文章

  1. 洛谷P2084 进制转换

    题目背景 无 题目描述 今天小明学会了进制转换,比如(10101)2 ,那么它的十进制表示的式子就是 : 1*2^4+0*2^3+1*2^2+0*2^1+1*2^0, 那么请你编程实现,将一个M进制的 ...

  2. 洛谷P1017 进制转换

    洛谷P1017 进制转换 题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 \(1*10 ...

  3. 洛谷p1017 进制转换(2000noip提高组)

    洛谷P1017 进制转换 题意分析 给出一个数n,要求用负R进制显示. n∈[-32768,32767].R ∈[-20,-2] 考察的是负进制数的转换,需要理解短除法. 看到这道题的时候,我是比较蒙 ...

  4. 洛谷——P1017 进制转换

    P1017 进制转换 题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1\times ...

  5. 洛谷——P1143 进制转换

    P1143 进制转换 题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进 ...

  6. 洛谷P1143 进制转换

    题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进制数,若n>10 ...

  7. 洛谷 P1143 进制转换

    P1143 进制转换 题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进 ...

  8. 集训作业 洛谷P1017 进制转换

    这个题的题目真的太恶心了. 重点是他的题目描述和他的目标没啥关系. 和最终目的有关系的只有这么一句话:”输出此负进制数及其基数,若此基数超过10,则参照16进制的方法处理.“ 我们通过看这句话可以发现 ...

  9. 洛谷 P1017 进制转换

    推荐洛谷 题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1*10^2+2*10^1+ ...

随机推荐

  1. redis-缓存穿透,缓存雪崩,缓存击穿,并发竞争

    目录 缓存穿透 定义 解决方案 利用互斥锁 采用异步更新策略 使用布隆过滤器 空置缓存 缓存雪崩 定义 解决方案 给缓存的加一个随机失效时间 使用互斥锁 双缓存策略 缓存击穿 定义 解决方案 使用互斥 ...

  2. Android点9图的运用

    在Android UI设计开发中,我们经常会用到一些图标.图片来做背景等. 相信很多同学都会遇到一个问题,就是我们让美工做好一张图,一个图标,呃,看起来挺好看的,但是放进app中,扩大或缩小.在不同分 ...

  3. python自动化测试学习笔记-4常用模块

    常用模块 1.os 2.sys 3.random 4.string 5.time 6.hashlib 一.os模块 os模块主要用来操作文件.目录,与操作系统无关.要使用os模块首先要导入OS模块,用 ...

  4. Python多线程、多进程

    1.from  multiprocessing import Process ;  from  threading import Thread 2.进程之间的数据传输 ,一般会使用到pipes, qu ...

  5. [转]mysql视图学习总结

    转自:http://www.cnblogs.com/wangtao_20/archive/2011/02/24/1964276.html 一.使用视图的理由是什么?1.安全性.一般是这样做的:创建一个 ...

  6. DataFrame编程模型初谈与Spark SQL

    Spark SQL在Spark内核基础上提供了对结构化数据的处理,在Spark1.3版本中,Spark SQL不仅可以作为分布式的SQL查询引擎,还引入了新的DataFrame编程模型. 在Spark ...

  7. Ambari架构及安装

    不多说,直接上干货! 1.什么是Ambari? 2.Ambari项目是由哪几部分构成的? 3.Ambari系统架构是如何组成的? 前言 Hadoop集群的管控一直是一个热门的话题,对于这样的一个应用场 ...

  8. facenet

    facenet dl  face recognition  一.运行facenet 验证lfw数据集效果: python2.7 src/validate_on_lfw.py ~/dataset/lfw ...

  9. JS——冒泡案例

    模态框 1.因为a链接和和顶级document都注册了单击事件,所以要阻止a链接向父级盒子冒泡,不然又会从document的单击事件走一遍 2.在document的单击事件中,只需要判断触发事件的目标 ...

  10. 字符串str

    字符串: #字符串的索引从0开始的,如果倒数最后一位是-1,索引的位置是唯一的.var1 = var[0:2] #从第一个字符到第2个字符var2 = var[:] #从第一个到最后var3 = va ...