Tuesday, March 1, 2022

Chessboard Distance

 The Chessboard Distance for any two points 

(X1,Y1) and (X2,Y2) on a Cartesian plane is defined as max(|X1X2|,|Y1Y2|).

You are given two points (X1,Y1) and (X2,Y2). Output their Chessboard Distance.

Note that, |P| denotes the absolute value of integer P. For example, |4|=4 and |7|=7.

Input Format

  • First line will contain T, the number of test cases. Then the test cases follow.
  • Each test case consists of a single line of input containing 4 space separated integers - X1,Y1,X2,Y2 - as defined in the problem statement.

Output Format

For each test case, output in a single line the chessboard distance between (X1,Y1) and (X2,Y2)

Constraints

  • 1T1000
  • 1X1,Y1,X2,Y2105

Subtasks

Subtask #1 (100 points): original constraints

Sample Input 1 

3
2 4 5 1
5 5 5 3
1 4 3 3

Sample Output 1 

3
2
2

Explanation

  • In the first case, the distance between (2,4) and (5,1) is max(|25|,|41|)=max(|3|,|3|)=3.

  • In the second case, the distance between (5,5) and (5,3) is max(|55|,|53|)=max(|0|,|2|)=2.

  • In the third case, the distance between (1,4) and (3,3) is max(|13|,|43|)=max(|2|,|1|)=2.

No comments:

Post a Comment

मुझे दिल में बसाना आसान नहीं....

पता है Recently i realised की मुझे दिल में बसाना आसान नहीं है बात-बात पे चिढ़ जाती हूं मैं दिल लगा लूं एक बार तो फिर ज़िद पे अड़...