1030B - Vasya and Cornfield - CodeForces Solution


geometry *1100

Please click on ads to support us..

Python Code:

def distance(x,y,c):
     return pow((x-c)**2 + (y-c)**2,0.5)



n,d = list(map(int,input().split()))
for _ in range(int(input())):
     x,y = list(map(int,input().split()))
     if(d <= x+y <= 2*n-d and -d <= x-y <= d):
          print("YES")
     else:
          print("NO")

C++ Code:

#include <bits/stdc++.h>
#define FOR(i, a, n) for (int i = a; i < int(n); ++ i)
#define ROF(i, a, n) for (int i = a; i > int(n); -- i)
using namespace std;
int main() {
	int n, d, m, a, b;
	cin >> n >> d >> m;
	FOR(i, 0, m) {
		cin >> a >> b;
		if (a + b >= d && a + b <= 2 * n - d && a - b >= -d && a - b <= d) 
		cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people