A 2D plane has a stack of radars (the radar has x, y coordinates, and a range r radius that can be detected). Now there is a car that passes through the range of y = 0 and y = 1 and cannot be detected by radar. If detected, the output Yes, otherwise the output No. (It can be considered that the car is a line length 1, along the line from x = 0 to the right)
Precautions
Radar number is n,n <= 1000.
the radar coordinates x is a nonnegative integer, y is an integer, and r is a positive integer.
Examples
give coordinates = [[0,2]], radius = [1], return "NO".
Explanation:
There is a radar at (0,2) that detects a circular area with a radius of 1 (0,2) and a small car that is not detected.
give coordinates = [[0,2],[1,2]], radius = [1,2], return "YES".
Explanation:
There is a radar at (0,2), which detects a circular region (0,2) with a radius of 2 and a circle (1,2) at the center of the circle, and a circular region (1,2) with a radius of 2. No. 2nd radar can detect the passing of a car.
Ideas
Whether the value of Y is detected only.
#ifndef c957_h #define C957_H #include <iostream> #include <string> #include <vector> using namespace
Std
struct point{int x;
int y;
Point (): X (0), y (0) {} (int a, int b): X (a), Y (b) {}}; Class Solution {public:/** * @param coordinates:the radars ' coordinate * @param radius:detection radius of Radars * @return: The car is detected or not/string radardetection (vector<point> &coordinates,
Vector<int> &radius) {//Write your code here if (Coordinates.empty () | | radius.empty ())
return "NO";
int len = Coordinates.size ();
for (int i = 0; i < len; ++i) {if (isdetected (COORDINATES[I].Y, radius[i)) {
return "YES";
} return "NO";
//Determine if it will detect that only the value of y coordinates is related to bool isdetected (int y, int radius) {if (y >= 0 && y <= 1)
return true; ElSe if (y > 1) {if (Y-radius < 1) return true;
else return false;
else {if (y + radius>0) return true;
else return false;
}
}
}; #endif