[ccAUG14] The Leaking Robot

描述 Description

Oh no! Chef’s robot from problem “Reach The Point” (RETPO) has broken up.

It’s old oil tank has got leaked, it is leaking oil now.

The robot start doing the following weird moves. While moving it keeps leaving a trace of oil on the path it’s been tracing.

Note that in a single step robot will move by one unit in the current direction it is moving.

Initially the robot is at position (0, 0).

In the beginning it goes 1 step to the East (i.e. In a single step, its x coordinate will increase by 1 unit.)

then 2 steps to the North, (i.e. In a single step, its y coordinate will increase by 1 unit.)

then 3 steps to the West, (i.e. In a single step, its x coordinate will decrease by 1 unit.)

then 4 steps to the South, (i.e. In a single step, its y coordinate will decrease by 1 unit.)

then 5 steps to the East,

and so on.

Thus each time the robot turns 90 degrees anti clockwise, and it will go one more step than before. Please view the following image to understand the moves. The red line in the example shows the path traced by the robot having traces of oil on it.

Now chef wants to know whether the point (X, Y) will have traces of oil on it or not.

输入格式 InputFormat

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

For each test case, there is a single line containing two space-separated integers X and Y.

输出格式 OutputFormat

For each test case, output a single line containing “YES” (without quotes) if robot will reach point (X, Y) and “NO” otherwise.

样例输入 SampleInput

3
3 3
3 5
0 0

样例输出 SampleOutput

YES
NO
YES


CodeChef CRAWA


把图画出来就好了。。。

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int i,j,t,n,m,l,r,k,z,y,x;
int T;
int main()
{
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d",&x,&y);
        t=abs(x)/2+abs(x)%2;
        if (x==0)
        {
            if (abs(y)%2==0) printf("YES\n");
            else printf("NO\n");
        }
        if (x>0)
        {
            if (x%2==0)
            {
                if (y<=2*t+1 && y>=1-2*t) printf("NO\n");
                else if (abs(y)%2==1) printf("NO\n");
                else printf("YES\n");
            }
            else
            {
                if (y<=2*t && y>=-2*(t-1)) printf("YES\n");
                else if (abs(y)%2==0) printf("YES\n");
                else printf("NO\n");
            }
        }
        if (x<0)
        {
            if (abs(x)%2==0)
            {
                if (y<=2*t && y>=-2*t) printf("YES\n");
                else if (abs(y)%2==0) printf("YES\n");
                else printf("NO\n");
            }
            else
            {
                if (y<=2*t-1 && y>=-2*t+1) printf("NO\n");
                else if (abs(y)%2==1) printf("NO\n");
                else printf("YES\n");
            }
        }
    }
    return 0;
}