题目来源:http://bailian.openjudge.cn/practice/1663/
1663:Number Steps
-----------------------------------------------------
总时间限制:
1000ms
内存限制:
65536kB
描述
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), andwrites the number (if any) that has been written at that point. (x, y)coordinates in the input are in the range 0...5000.
输入
The first line of the input is N, the number of testcases for this problem. In each of the N following lines, there is x, and yrepresenting the coordinates (x, y) of a point.
输出
For each point in the input, write the number written atthat point or write No Number if there is none.
样例输入
3
4 2
6 6
3 4
样例输出
6
12
No Number
-----------------------------------------------------
解题思路
没意思的题目
-----------------------------------------------------
代码
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int N, a, b, ans;
vector<int> ANS;
cin >> N;
int i=0;
for (i=0; i<N; i++)
{
cin >> a >> b;
if(a>=0 && b>=0)
{
if(a==b && a%2==0)
{
ans = 2*a;
}
else if(a==b && a%2==1)
{
ans = 2*a-1;
}
else if(a==(b+2) && b%2==0)
{
ans = 2*b+2;
}
else if(a==(b+2) && b%2==1)
{
ans = 2*b+1;
}
else
{
ans = -1; // "No number"
}
}
else
{
ans = -1; // outside the first quadrant
}
ANS.push_back(ans);
}
for (i=0;i<N;i++)
{
if(ANS[i]>=0)
{
cout << ANS[i] << endl;
}
else
{
cout << "No Number" << endl;
}
}
return 0;
}