Celex Update codeforces 1358 C

. Celex Update
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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) is at the intersection of x-th row and y-th column. Upper left cell (1,1) contains an integer 1.
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) in one step you can move to the cell (x+1,y) or (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) to another given cell (x2,y2), if you can only move one cell down or right.

Formally, consider all the paths from the cell (x1,y1) to cell (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 t (1≤t≤57179) — the number of test cases.

Each of the following t lines contains four natural numbers x1, y1, x2, y2 (1≤x1≤x2≤109, 1≤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
inputCopy
4
1 1 2 2
1 2 2 4
179 1 179 100000
5 7 5 7
outputCopy
2
3
1
1
Note
In the first test case there are two possible sums: 1+2+5=8 and 1+3+5=9.
在這裏插入圖片描述
解法一
剛開始感覺是求組合數,C31 ,C42之類的,但是,如果仔細考慮一下,這道題可以轉化爲最大值-最小值,因爲每個情況的值排列在一起是11 ,12 ,13,14 這種情況,那麼種類個數
就爲14-11+1=4;而求最大值和最小值不好求,但是可以直接求最大值與最小值的差,
在這裏插入圖片描述
從1到13,最大值-最小值=(1+3+6+9+13)-(1+2+4+8+13);去除1和13;**那麼就是對角線上的值相減,而對腳線上的值相減,3-2=1,這個值就是方塊2和方塊3的共同的邊角的點,有一個點,爲1,
6-4=2;方塊6方塊5的共同的邊角的點,方塊5與方塊4共同的邊角的點,有兩個點爲2,那麼就轉化爲了求方塊與方塊之間的共同的邊角點的個數,**整個大方塊的邊界除外,那麼點的個數就爲(3-1)(3-1)=4;也就是(x2-x1)(y2-y1)。最終結果就是(x2-x1)*(y2-y1)+1。
解法二 大膽一點,瞎猜一下,嗯,蒙對了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章