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 nm 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 nmx1y1x2y2, 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

Input
2
4 4 1 1 3 3
4 3 1 1 2 2
Output
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的更多相关文章

  1. 在ros中使用rplidar Laser发布scan数据--25

    原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 由于市面上买的激光雷达价格太贵了.所以在学习时会造成很大的经济压力.但是最近好多做机器人核心组件的公司都 ...

  2. L'opzione di luce del puntatore laser

    Prima di tutto, sono di buone dimensioni, non i 'mini' puntatori laser che altri stanno vendendo. È ...

  3. Il laser che è chiaramente visibile

    Prima di quel tempo ho ottenuto questo potente puntatore laser 500mW, non so davvero come questo dis ...

  4. La nuova tecnologia del puntatore laser

    Il potente puntatore laser 20000 mW viene fornito di serie con gestione termica e driver laser di qu ...

  5. La protezione del puntatore laser

    Questo puntatore laser è sempre sufficientemente efficiente per eseguire il test più accurato su qua ...

  6. Kalman filter, Laser/Lidar measurement

    You can download this project from https://github.com/lionzheng10/LaserMeasurement The laser measure ...

  7. Comparison of Laser SLAM and Visual SLAM

    Comparison of Laser SLAM and Visual SLAM 目前,SLAM技术广泛应用于机器人.无人机.无人机.AR.VR等领域,依靠传感器可以实现机器的自主定位.测绘.路径规划 ...

  8. 【High-Speed and Accurate Laser Scan Matching Using Classified Features】

    所谓的"分类特征",就是把特征分成 1. 旋转特征:用直线表示 2. 平移特征,用撕裂点和临界点表示 最大的创新点 应该就是下面的分组吧 匹配的时候,用RANSAC 或者动态规划, ...

  9. 【A Global Line Matching Algorithm for 2D Laser Scan Matching in Regular Environment】

    只看了前面的部分,灭有看实验,觉得整体风格比较傻白甜,与我的想法不谋而合.简单明了,用起来应该比较方便. 初步探测:如果有直线,就给线性插值一下. 分级聚类:利用简单的阈值给聚类了一下,分成了段段. ...

随机推荐

  1. Harbor私有仓库搭建

    1.安装docker yum install -y dockersystemctl start dockersystemctl enable docker 2.安装docker-compose 1.下 ...

  2. javascript;Jquery;获取JSON对象,无刷新分页,异步加载,异步删除,实例。

    AjaxNewsList: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> < ...

  3. jQuery自动轮播图片焦点图

    在线演示 本地下载

  4. 2017最全的php面试题目及答案总结

    最近在网上看到很多的小伙伴们都在询问如何应对php面试,这个对于有工作经验和实战项目的小伙伴来说是没什么问题的,但是对于刚刚学习完php的小伙伴们.php面试却是一个很重要的一步,那么今天php中文网 ...

  5. 20145240《Java程序设计》第七周学习总结

    20145240<Java程序设计>第七周学习总结 教材学习内容总结 12.1认识Lambda语法 12.1.1Lambda语法概览 在java中引入了Lambda的同时,与现有API维持 ...

  6. freemarker日志实现过程分析

    freemarker有自己的log类,这是一个抽象类,具体的日志打印委托给classpath里面合适的日志jar包来执行,寻找合适日志jar的查找顺序是:Apache Log4J, Apache Av ...

  7. 堆栈在linux内存中的使用

    链接:https://www.zhihu.com/question/57013926/answer/151506606 1.Linux 内核中使用 task_struct 作为进程描述符,该结构定义在 ...

  8. 【P1886】滑动窗口(单调队列→线段树→LCT)

    这个题很友好,我们可以分别进行简单难度,中等难度,恶心难度来做.然而智商没问题的话肯定是用单调队列来做... 板子题,直接裸的单调队列就能过. #include<iostream> #in ...

  9. linux基础(5)-用户及权限

    用户与组 用户:使用linux时,需要以用户的身份登陆 组    :用来方便组织管理用户   用户种类 -root用户(ID为0的用户为root用户) -系统用户(1-499) -普通用户(500以上 ...

  10. Apache Phoenix基本操作-1

    本篇我们将介绍phoenix的一些基本操作. 1. 如何使用Phoenix输出Hello World? 1.1 使用sqlline终端命令 sqlline.py SZB-L0023780:2181:/ ...