ArticleDirectory
Digital step time limit: 1000 ms memory limit: 10000 k total time limit: 3000 Ms
Description:
Starting from the point (0, 0) of the plane coordinate, we can write all non-negative integers 0, 1, 2 ,.......
For example, 1, 2, and 3 are written at (1, 1), (2, 0), and (3, 1) respectively. Then we can continue to write all the numbers in this format:
Now you need to writeProgramRead the coordinate points (x, y) to determine the number (if any) at this point. (x, y) are all numbers between 0 and 5000.
Input:
The first line is the number n (n <1000), indicating the number of test data. Next, there will be n with test data, and each row will have
The two numbers represent the coordinates of X and Y, respectively.
Output:
For the X and Y input in each row, the number of the vertex is output, with one row. If there is no number at this point, print no number.
Input example:
3
4 2
6 6
3 4
Output example:
6
12
No number
Tip:
Source:
2006 Northwestern University Program Design Competition finals E
Code:
-
- # Include <stdio. h>
-
- # Include <stdlib. h>
-
-
- Int main ()
-
- {
-
- Int N;
- Int I, J;
-
- Scanf ("% d", & N );
-
- Int **;
-
- A = (INT **) malloc (N * sizeof (int *));
-
- For (I = 0; I <n; I ++)
-
- {
-
- A [I] = (int *) malloc (2 * sizeof (INT ));
-
- }
-
- For (I = 0; I <n; I ++)
-
- {
-
- For (j = 0; j <2; j ++)
-
- {
-
- Scanf ("% d", & A [I] [J]);
-
- }
-
- }
-
- For (I = 0; I <n; I ++)
-
- {
-
- If (A [I] [0] % 2 = 0 & A [I] [1] % 2 = 0)
-
- Printf ("% d \ n", a [I] [0] + A [I] [1]);
-
- Else if (a [I] [0] % 2! = 0 & A [I] [1] % 2! = 0)
-
- Printf ("% d \ n", a [I] [0] + A [I] [1]-1 );
-
- Else
-
- Printf ("no number \ n ");
-
- }
- Return 0;
-
- }
-
-