A. Square
A square of positive (strictly greater than 000) area is located on the coordinate plane, with sides parallel to the coordinate axes. You are given the coordinates of its corners, in random order. Your task is to find the area of the square.
Input
Each test consists of several testcases. The first line contains one integer ttt (1≤t≤1001 \le t \le 1001≤t≤100) — the number of testcases. The following is a description of the testcases.
Each testcase contains four lines, each line contains two integers xi,yix_i, y_ixi,yi (−1000≤xi,yi≤1000-1000\le x_i, y_i\le 1000−1000≤xi,yi≤1000), coordinates of the corners of the square.
It is guaranteed that there is a square with sides parallel to the coordinate axes, with positive (strictly greater than 000) area, with corners in given points.
Output
For each test case, print a single integer, the area of the square.
Example
input
3
1 2
4 5
1 5
4 2
-1 1
1 -1
1 1
-1 -1
45 11
45 39
17 11
17 39
output
9
4
784
Tutorial
因为给出的四个点围起来是一个边与坐标轴平行的正方形,所以如果 xxx 的值相等,那 yyy 值的差就是边长,如果 yyy 的值相等,那 xxx 值的差就是边长,直接找出一条边的长度即可
Solution
for _ in range(int(input())):
a = sorted(tuple(map(int, input().split())) for _ in range(4))
print((a[1][1] - a[0][1]) ** 2)
B. Arranging Cats
In order to test the hypothesis about the cats, the scientists must arrange the cats in the boxes in a specific way. Of course, they would like to test the hypothesis and publish a sensational article as quickly as possible, because they are too engrossed in the next hypothesis about the phone's battery charge.
Scientists have nnn boxes in which cats may or may not sit. Let the current state of the boxes be denoted by the sequence b1,…,bnb_1, \dots, b_nb1,…,bn: bi=1b_i = 1bi=1 if there is a cat in box number iii, and bi=0b_i = 0bi=0 otherwise.
Fortunately, the unlimited production of cats has already been established, so in one day, the scientists can perform one of the following operations:
- Take a new cat and place it in a box (for some iii such that bi=0b_i = 0bi=0, assign bi=1b_i = 1bi=1).
- Remove a cat from a box and send it into retirement (for some iii such that bi=1b_i = 1bi=1, assign bi=0b_i = 0bi=0).
- Move a cat from one box to another (for some i,ji, ji,j such that bi=1,bj=0b_i = 1, b_j = 0bi=1,bj=0, assign bi=0,bj=1b_i = 0, b_j = 1bi=0,bj=1).
It has also been found that some boxes were immediately filled with cats. Therefore, the scientists know the initial position of the cats in the boxes s1,…,sns_1, \dots, s_ns1,…,sn and the desired position f1,…,fnf_1, \dots, f_nf1,…,fn.
Due to the large amount of paperwork, the scientists do not have time to solve this problem. Help them for the sake of science and indicate the minimum number of days required to test the hypothesis.
Input
Each test consists of several test cases. The first line contains a single integer ttt (1≤t≤1041 \le t \le 10^41≤t≤104) — the number of test cases. This is followed by descriptions of the test cases.
Each test case consists of three lines.
The first line of each test case contains a single integer nnn (1≤n≤1051 \le n \le 10^51≤n≤105) — the number of boxes.
The second line of each test case contains a string sss of nnn characters, where the iii-th character is ‘1’ if there is a cat in the iii-th box and ‘0’ otherwise.
The third line of each test case contains a string fff of nnn characters, where the iii-th character is ‘1’ if there should be a cat in the iii-th box and ‘0’ otherwise.
It is guaranteed that in a test the sum of nnn over all test cases does not exceed 10510^5105.
Output
For each test case, output a single integer on a separate line — the minimum number of operations required to obtain the desired position from the initial position. It can be shown that a solution always exists.
Example
input
6
5
10010
00001
1
1
1
3
000
111
4
0101
1010
3
100
101
8
10011001
11111110
output
2
0
3
2
1
4
Note
In the first test case, you can first move the cat from the first box to the fifth, and then remove the