Number steps)

Source: Internet
Author: User
Number steps

Time limit:1 second Memory limit:32768 KB
Starting from point (0, 0) on a plane, we have written all non-negative
Integers 0, 1, 2,... as shown in the figure. For example, 1, 2, and 3 has been
Written at points (1, 1), (2, 0), and (3, 1) respectively and this pattern has
Continued.

You are to write a program that reads the coordinates of a point (x, y), and
Writes the number (if any) that has been written at that point. (x, y)
Coordinates in the input are in the range 0... 5000.

Input

The first line of the input is N, the number of test
Cases for this problem. In each of the N following lines, there is X, and Y
Representing the coordinates (x, y) of a point.

Output

For each point in the input, write the number
Written at that point or write no number if there is none.

Sample Input

3
4 2
6 6
3 4

Sample output

6
12
No number

Answer: View code

 Int  Main ()
{
Int N, I;
Scanf ( " % D " , & N ); // N indicates the number of test data in the input file.
Int X, Y;
For (I = 0 ; I < N; I ++ ) // Process n test data in the input file
{
Scanf ( " % D " , & X, & Y ); // Each test data contains two integers.
Int Num; // Non-negative integer at the (x, y) coordinate point
If (Y ! = X && Y ! = X - 2 )
{
Num = - 1 ;
}
Else
{
If (Y = X && X % 2 = 0 )
{
Num = 2 * X;
}
Else If (Y = X && X % 2 ! = 0 )
{
Num = 2 * X - 1 ;
}
Else If (Y = X - 2 && X % 2 = 0 )
{
Num = 2 * X - 2 ;
}
Else
{
Num = 2 * X - 3 ;
}
}
If (Num = - 1 ) Printf ( " No number \ n " );
Else Printf ( " % D \ n " , Num );
}
Return 1 ;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.