zoukankan      html  css  js  c++  java
  • Codeforces Round #645 (Div. 2) C. Celex Update(思维)

    During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows:

    The cell with coordinates (x,y)(x,y) is at the intersection of xx -th row and yy -th column. Upper left cell (1,1)(1,1) contains an integer 11 .

    The developers of the SUM function don't sleep either. Because of the boredom, they teamed up with the developers of the RAND function, so they added the ability to calculate the sum on an arbitrary path from one cell to another, moving down or right. Formally, from the cell (x,y)(x,y) in one step you can move to the cell (x+1,y)(x+1,y) or (x,y+1)(x,y+1) .

    After another Dinwows update, Levian started to study "Celex-2021" (because he wants to be an accountant!). After filling in the table with the GAZ-GIZ function, he asked you to calculate the quantity of possible different amounts on the path from a given cell (x1,y1)(x1,y1) to another given cell (x2,y2(x2,y2 ), if you can only move one cell down or right.

    Formally, consider all the paths from the cell (x1,y1)(x1,y1) to cell (x2,y2)(x2,y2) such that each next cell in the path is located either to the down or to the right of the previous one. Calculate the number of different sums of elements for all such paths.

    Input

    The first line contains one integer tt (1t571791≤t≤57179 ) — the number of test cases.

    Each of the following tt lines contains four natural numbers x1x1 , y1y1 , x2x2 , y2y2 (1x1x21091≤x1≤x2≤109 , 1y1y21091≤y1≤y2≤109 ) — coordinates of the start and the end cells.

    Output

    For each test case, in a separate line, print the number of possible different sums on the way from the start cell to the end cell.

    Example
    Input
    Copy
    4
    1 1 2 2
    1 2 2 4
    179 1 179 100000
    5 7 5 7
    
    Output
    Copy
    2
    3
    1
    1
    借用一下官方题解的一张图

    会发现图中标出的路线每个田字格右上和左下的数字相差1,而这两条路线的数字之和只差1。一直往右再往下是和最小的走法。往右再往下的路径为一条,带有往下再往右拐点
    的路径(图中紫色路径)为(x1-x2)*(y1-y2)条,加起来输出即可。

     
    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int x1,y1,x2,y2;
            cin>>x1>>y1>>x2>>y2;
            cout<<(long long)(x2-x1)*(y2-y1)+1<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Apple http live streaming 不支持windows?
    CDN设计:[笔记]Analysis of Enterprise Media Server Workloads
    牛项目 Harvest
    一些校园招聘的题目和分析
    关于pdf转doc (word) 的工具 Solid Converter PDF
    A CAP Solution (Proving Brewer Wrong)
    6"电纸书/电子书 PaperCrop pdf重排使用心得
    CDN设计 层级化的cache_A
    Berkeley DB Hash、Btree、Queue、Recno 选择
    PowerDesigner 学习系列 简单操作
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12970740.html
Copyright © 2011-2022 走看看