zoukankan      html  css  js  c++  java
  • 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 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 ≤ 1091 ≤ x1, x2 ≤ n1 ≤ 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 * 2 + (sx - tx) * (sy - ty);
            else cout<<n * m - sx * sy * 2;
            cout<<endl;
        }
    }
  • 相关阅读:
    Mysql存储引擎
    数据库事务的四大特性以及事务的隔离级别
    万万没想到,面试中,连 ClassLoader类加载器 也能问出这么多问题
    万万没想到,JVM内存区域的面试题也可以问的这么难?
    SQL Server读取及导入Excel数据
    SQL Server加密与解密
    线程之间如何通信
    mybatis 批量更新 批量添加
    vue echarts 从后台获取数据形成饼图,柱状图,折线图
    vue 视频播放
  • 原文地址:https://www.cnblogs.com/8023spz/p/8437012.html
Copyright © 2011-2022 走看看