Radar Detection-lintcode

Source: Internet
Author: User
Tags lintcode radar

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.