output

standard output

Vasya owns a cornfield which can be defined with two integers n

and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0,d),(d,0),(n,n−d) and (n−d,n)

.

B. Vasya and Cornfield An example of a cornfield with n=7

and d=2

.

Vasya also knows that there are m

grasshoppers near the field (maybe even inside it). The i-th grasshopper is at the point (xi,yi)

. Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

Help Vasya! For each grasshopper determine if it is inside the field (including the border).

Input

The first line contains two integers n

and d (1≤d<n≤100

).

The second line contains a single integer m

(1≤m≤100

) — the number of grasshoppers.

The i

-th of the next m lines contains two integers xi and yi (0≤xi,yi≤n) — position of the i

-th grasshopper.

Output

Print m

lines. The i-th line should contain "YES" if the position of the i-th grasshopper lies inside or on the border of the cornfield. Otherwise the i

-th line should contain "NO".

You can print each letter in any case (upper or lower).

Examples

Input

Copy

7 2
4
2 4
4 1
6 3
4 5

Output

Copy

YES
NO
NO
YES

Input

Copy

8 7
4
4 4
2 8
8 1
6 1

Output

Copy

YES
NO
YES
YES

题意:

       给你一个矩阵,让你判断点是否在矩阵内,边上也算。

思路:

       首先我们可以观察出这个矩阵和四个三角形可以构造出一个大的正方形,所以我们只需要判断出这点在这正方形内且不在这个四个三角形内就OK了。

code:

     

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int n, d, m,tempx,tempy;
int yy(int x1, int y1, int x2, int y2, int x)
{
	return (float)(x - x1)*(y1 - y2) / (x1 - x2) + y1;
}
bool pang(int x, int y)
{
	if (x > n || y > n)
		return 0;
	else
	{
		if (yy(d, 0, 0, d, x) > y)
		{
			return 0;
		}
		if (yy(d, 0, n, n - d, x) > y)
		{
			return 0;
		}
		if (yy(n-d, n, n, n-d, x) < y)
		{
			return 0;
		}
		if (yy(0, d, n - d, n, x) < y)
		{
			return 0;
		}
		return 1;
	}
}
int main()
{
	cin >> n >> d;
	cin >> m;
	for (int i = 1; i <= m; i++)
	{
		cin >> tempx >> tempy;
		if (pang(tempx, tempy))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}

 

相关文章:

  • 2021-10-27
  • 2021-07-05
  • 2022-01-20
  • 2021-06-12
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
猜你喜欢
  • 2021-12-21
  • 2021-06-18
  • 2022-12-23
  • 2022-01-11
  • 2021-06-02
相关资源
相似解决方案