cf 512 div2 B. Vasya and Cornfield
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 nn and dd (1≤d<n≤1001≤d<n≤100).
The second line contains a single integer mm (1≤m≤1001≤m≤100) — the number of grasshoppers.
The ii-th of the next mm lines contains two integers xixi and yiyi (0≤xi,yi≤n0≤xi,yi≤n) — position of the ii-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
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
Note
The cornfield from the first example is pictured above. Grasshoppers with indices 11 (coordinates (2,4)(2,4)) and 44 (coordinates (4,5)(4,5)) are inside the cornfield.
The cornfield from the second example is pictured below. Grasshoppers with indices 11 (coordinates (4,4)(4,4)), 33 (coordinates (8,1)(8,1)) and 44(coordinates (6,1)(6,1)) are inside the cornfield.
給出4個點組成一個矩形,給出n個查詢點,問這些點是否在矩形內。
第一次看挺難,給出的4個點,可以推一下。發現斜率都是1或-1.
然後就判斷就好了
#pragma GCC optimize(2) #include<stdio.h> #include<algorithm> #include<string.h> #include<queue> using namespace std; const int maxn = 500; const int inf = 0x3f3f3f3f; typedef long long ll; int a[maxn]; int main() { //freopen("C://input.txt", "r", stdin); int n; int flag = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); if (a == 1) { flag = 1; } } if (flag == 1) { printf("HARD\n"); } else { printf("EASY\n"); } return 0; }