洛谷 P2084 进制转换
题目描述
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.
输入输出样例
说明
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 进制转换的更多相关文章
- 洛谷P2084 进制转换
题目背景 无 题目描述 今天小明学会了进制转换,比如(10101)2 ,那么它的十进制表示的式子就是 : 1*2^4+0*2^3+1*2^2+0*2^1+1*2^0, 那么请你编程实现,将一个M进制的 ...
- 洛谷P1017 进制转换
洛谷P1017 进制转换 题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 \(1*10 ...
- 洛谷p1017 进制转换(2000noip提高组)
洛谷P1017 进制转换 题意分析 给出一个数n,要求用负R进制显示. n∈[-32768,32767].R ∈[-20,-2] 考察的是负进制数的转换,需要理解短除法. 看到这道题的时候,我是比较蒙 ...
- 洛谷——P1017 进制转换
P1017 进制转换 题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1\times ...
- 洛谷——P1143 进制转换
P1143 进制转换 题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进 ...
- 洛谷P1143 进制转换
题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进制数,若n>10 ...
- 洛谷 P1143 进制转换
P1143 进制转换 题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共有三行,第一行是一个正整数,表示需要转换的数的进制n(2≤n≤16),第二行是一个n进 ...
- 集训作业 洛谷P1017 进制转换
这个题的题目真的太恶心了. 重点是他的题目描述和他的目标没啥关系. 和最终目的有关系的只有这么一句话:”输出此负进制数及其基数,若此基数超过10,则参照16进制的方法处理.“ 我们通过看这句话可以发现 ...
- 洛谷 P1017 进制转换
推荐洛谷 题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1*10^2+2*10^1+ ...
随机推荐
- [Swift通天遁地]七、数据与安全-(3)Cocopods的安装和开源类库对JSON的解析
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- python自动化测试学习笔记-5常用模块
上一次学习了os模块,sys模块,json模块,random模块,string模块,time模块,hashlib模块,今天继续学习以下的常用模块: 1.datetime模块 2.pymysql模块(3 ...
- 题解报告:hdu 1279 验证角谷猜想
Problem Description 数论中有许多猜想尚未解决,其中有一个被称为“角谷猜想”的问题,该问题在五.六十年代的美国多个著名高校中曾风行一时,这个问题是这样描述的:任何一个大于一的自然数, ...
- Offer收割_5
训练 投入 欲望. ---贾森博尔特 第一题:二分枚举答案,check时候模拟一下即可. 时间复杂度: O(n*logn). 第二题: 描述 小Hi在虚拟世界中有一只小宠物小P.小P有K种属性,每种 ...
- 【Leetcode146】LRU Cache
问题描述: 设计一个LRU Cache . LRU cache 有两个操作函数. 1.get(key). 返回cache 中的key对应的 val 值: 2.set(key, value). 用伪代码 ...
- layer实现在前台删除前确认弹出框,并回调后台删除事件
最近遇到一些问题,用layer提示消息框,比如删除时,提示消息确定后 return false时,则不管用了,因为layer不支持阻塞,下面就解决一下这个问题:(本文使用Xcode,如要学习,请复下面 ...
- Unity学习-软件的基本操作(二)
基本操作 1:Scene中 以小手显示,平移画布,与鼠标中键一样 2:平移 游戏对象,组件的 Position属性 也可设置 3:旋转 游戏对象,组件的 Rotation属性 也可设置 4:缩放 游戏 ...
- Manacher 学习笔记
\(\\\) \(Manacher\) 一种常用的字符串算法,用于处理一些回文字符相关的问题. 回文串:从前向后和从后向前输出一致. 回文中心:以这里开始,每次向外左右各扩展一个字符得到的回文串的中心 ...
- node(koa)微信公众号接口认证
使用微信测试号, 花生壳内网穿透 需要注意 token 两边都是自定义, 需要保持一致, const Koa = require('koa') const sha1 = require('sha1') ...
- Ruby开发环境的搭建
1.Ruby的下载 https://rubyinstaller.org/downloads/ 2.Ruby的安装 3.Eclipse配置Ruby开发环境 插件地址:http://rubyeclipse ...