Laser
Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of n × m cells and a robotic arm. Each cell of the field is a 1 × 1 square. The robotic arm has two lasers pointed at the field perpendicularly to its surface. At any one time lasers are pointed at the centres of some two cells. Since the lasers are on the robotic hand, their movements are synchronized — if you move one of the lasers by a vector, another one moves by the same vector.
The following facts about the experiment are known:
- initially the whole field is covered with a chocolate bar of the size n × m, both lasers are located above the field and are active;
 - the chocolate melts within one cell of the field at which the laser is pointed;
 - all moves of the robotic arm should be parallel to the sides of the field, after each move the lasers should be pointed at the centres of some two cells;
 - at any one time both lasers should be pointed at the field. Petya doesn't want to become a second Gordon Freeman.
 
You are given n, m and the cells (x1, y1) and (x2, y2), where the lasers are initially pointed at (xi is a column number, yi is a row number). Rows are numbered from 1 to m from top to bottom and columns are numbered from 1 to n from left to right. You are to find the amount of cells of the field on which the chocolate can't be melted in the given conditions.
Input
The first line contains one integer number t (1 ≤ t ≤ 10000) — the number of test sets. Each of the following t lines describes one test set. Each line contains integer numbers n, m, x1, y1, x2, y2, separated by a space (2 ≤ n, m ≤ 109, 1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m). Cells (x1, y1) and (x2, y2) are distinct.
Output
Each of the t lines of the output should contain the answer to the corresponding input test set.
Example
2
4 4 1 1 3 3
4 3 1 1 2 2
8
2 画个图就知道了,一共两种情况,一种是覆盖的两部分各在一角没有重叠,另一种是有重叠,有重叠就用容斥原理。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath> using namespace std;
int t;
long long m,n,x_1,x_2,y_1,y_2;
int main()
{
scanf("%d",&t);
while(t --)
{
scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&x_1,&y_1,&x_2,&y_2);
long long sx = n - abs(x_1 - x_2),sy = m - abs(y_1 - y_2);
long long tx = abs(x_1 - x_2),ty = abs(y_1 - y_2);
if(tx < sx && ty < sy)cout<<n * m - sx * sy * + (sx - tx) * (sy - ty);
else cout<<n * m - sx * sy * ;
cout<<endl;
}
}
Laser的更多相关文章
- 在ros中使用rplidar Laser发布scan数据--25
		
原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 由于市面上买的激光雷达价格太贵了.所以在学习时会造成很大的经济压力.但是最近好多做机器人核心组件的公司都 ...
 - L'opzione di luce del puntatore laser
		
Prima di tutto, sono di buone dimensioni, non i 'mini' puntatori laser che altri stanno vendendo. È ...
 - Il laser che è chiaramente visibile
		
Prima di quel tempo ho ottenuto questo potente puntatore laser 500mW, non so davvero come questo dis ...
 - La nuova tecnologia del puntatore laser
		
Il potente puntatore laser 20000 mW viene fornito di serie con gestione termica e driver laser di qu ...
 - La protezione del puntatore laser
		
Questo puntatore laser è sempre sufficientemente efficiente per eseguire il test più accurato su qua ...
 - Kalman filter, Laser/Lidar measurement
		
You can download this project from https://github.com/lionzheng10/LaserMeasurement The laser measure ...
 - Comparison of Laser SLAM and Visual SLAM
		
Comparison of Laser SLAM and Visual SLAM 目前,SLAM技术广泛应用于机器人.无人机.无人机.AR.VR等领域,依靠传感器可以实现机器的自主定位.测绘.路径规划 ...
 - 【High-Speed and Accurate Laser Scan Matching Using Classified Features】
		
所谓的"分类特征",就是把特征分成 1. 旋转特征:用直线表示 2. 平移特征,用撕裂点和临界点表示 最大的创新点 应该就是下面的分组吧 匹配的时候,用RANSAC 或者动态规划, ...
 - 【A Global Line Matching Algorithm for 2D Laser Scan Matching in Regular Environment】
		
只看了前面的部分,灭有看实验,觉得整体风格比较傻白甜,与我的想法不谋而合.简单明了,用起来应该比较方便. 初步探测:如果有直线,就给线性插值一下. 分级聚类:利用简单的阈值给聚类了一下,分成了段段. ...
 
随机推荐
- bootstrap插件实用方法
			
完全通过js來配置 <p><a id="YOUR_BUTTON_FOR_POPOVER" class="btn btn-primary" ro ...
 - curl操作封装
			
<?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $url 请求的url ...
 - $.queue() 与 $.dequeue() -- 队列
			
JQuery 运用队列为动画模块服务,但好像它应该有更多用处,我觉得的,那试试就知道咯. 简单的来讲,它就是形成队列和出列, 也就因此可以进行很有规律的回调和延时了呀(暂停感觉有难度),当然这就是后面 ...
 - ubuntu里设置从串口登录
			
1) Create a file called /etc/init/ttyS0.conf containing the following: # ttySAC0 - getty # # This se ...
 - MySql 5.7 详细参数说明
			
max_connections: 允许客户端并发连接的最大数量,默认值是151,一般将该参数设置为500-2000 max_connect_errors: 如果客户端尝试连接的错误数量超过这个参数设置 ...
 - css异步加载
			
<link rel="preload" href="mystyles.css" as="style" onload="thi ...
 - MongoDB快速入门(六)- 更新文档
			
更新文档 MongoDB的update()和save()方法用于更新文档到一个集合. update()方法将现有的文档中的值更新,而save()方法使用传递到save()方法的文档替换现有的文档. M ...
 - juniper常用命令(二)
			
Juniper防火墙基本命令 常用查看命令 Get int查看接口配置信息 Get int ethx/x查看指定接口配置信息 Get mip查看映射ip关系 Get route查看路由表 Get po ...
 - hibernate集合的加载策略
			
在集合方配置lazy和fetch的方式,默认的是lazy为true,fetch为select,lazy有true,extra和false,true和extra都是懒加载,只是extra比true更懒, ...
 - 进程【TLCL】
			
ps命令 ps x 加上 "x" 选项(注意没有开头的 "-" 字符),告诉 ps 命令,展示所有进程,不管它们由什么 终端(如果有的话)控制. 在 TTY 一 ...