题目:Vasya and Cornfield
题意:给出两个整数n,d,代表有一个在第一象限的矩形,坐标是(0,d) (d,0) (n,n-d) (n-d,n),再给出一些点的坐标,求出这些点是否在矩形中。
思路:分类讨论下。
代码:
#include<bits/stdc++.h> using namespace std;#define ll long long #define inf (1<<30) #define read(x) scanf("%d",&x) #define maxn 100int n,d; int m; int a[maxn+5];void readin() {
read(n);read(d);read(m);if(d<=n-d) for(int i=1;i<=m;i++) {
int x,y;read(x);read(y);if(x<=d&&y<=d) {
if(x+y>=d) printf("YES\n");else printf("NO\n");} else if(x>=n-d&&y>=n-d) {
if(x+y<=2*n-d) printf("YES\n");else printf("NO\n");} else {
if(y-x>=-d&&y-x<=d) printf("YES\n");else printf("NO\n");}}else for(int i=1;i<=m;i++) {
int x,y;read(x);read(y);if(x<=n-d&&y>=d) {
if(y-x<=d) printf("YES\n");else printf("NO\n");} else if(x>=d&&y<=n-d) {
if(x-y<=d) printf("YES\n");else printf("NO\n");} else {
if((x+y<d)||(x+y>n*2-d)) printf("NO\n");else printf("YES\n");}} }int main() {
readin();return 0; }