Codeforces Round #512(Div2) B.Vasya and Cornfield

B. Vasya and Cornfield

time limit per test
1 second
memory limit per test
256 megabytes
input:standard input
output:standard output

Vasya owns a cornfield which can be defined with two integers nn and dd. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0,d),(d,0),(n,n−d)(0,d),(d,0),(n,n−d) and (n−d,n)(n−d,n).

An example of a cornfield with n=7n=7 and d=2d=2.

Vasya also knows that there are mm grasshoppers near the field (maybe even inside it). The ii-th grasshopper is at the point (xi,yi)(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 mm lines. The ii-th line should contain “YES” if the position of the ii-th grasshopper lies inside or on the border of the cornfield. Otherwise the ii-th line should contain “NO”.You can print each letter in any case (upper or lower).

Examples

input

7 2
4
2 4
4 1
6 3
4 5

output

YES
NO
NO
YES

input

8 7
4
4 4
2 8
8 1
6 1

output

YES
NO
YES
YES

Note

The cornfield from the first example is pictured above. Grasshoppers with indices 1 (coordinates (2,4)) and 4 (coordinates (4,5)) are inside the cornfield.
The cornfield from the second example is pictured below. Grasshoppers with indices 1 (coordinates (4,4)), 3 (coordinates (8,1)) and 4 (coordinates (6,1)) are inside the cornfield.

题解

题目大意就是给定 n 和 d ,在(0,d),(d,0),(n,n−d) 和 (n−d,n)这四个点构成的矩形里,给出 m 次询问,再给出点的坐标,询问此点是否在这个矩形内。可以通过叉积来计算点是否在矩形内(之后补充,再次挖坑…)。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std ;

typedef struct{
double x ;
double y ;
}point ;

double xmulti( point p1 , point p2 , point p0 ){
return ((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y)) ;
}

int main(){
int n , d ;
while ( cin >> n >> d ){
int m ;
cin >> m ;
point p1 , p2 , p3 , p4 ;
p1.x = 0 ;
p1.y = d ;
p2.x = d ;
p2.y = 0 ;
p3.x = n ;
p3.y = n - d ;
p4.x = n - d ;
p4.y = n ;
for ( int i = 0 ; i < m ; i ++ ){
point p0 ;
cin >> p0.x >> p0.y ;
if ( xmulti( p1 , p2 , p0 ) * xmulti( p3 , p4 , p0 ) >= 0
&& xmulti( p2 , p3 , p0 ) * xmulti( p4 , p1 , p0 ) >= 0 ){
cout << "YES" << endl ;
}else{
cout << "NO" << endl ;
}
}
}
return 0 ;