POJ 1328 Radar Installation

Source: Internet
Author: User
Tags radar

Title Link: http://poj.org/problem?id=1328

Greedy.

Read a few problem-solving reports are said to be water problems, the problem-solving method is very simple, but do not understand why ...

Many online code submissions are WA's, really enchanted ...

For each small island, there is an interval on the coast that can cover it. Sort the interval by the left boundary, then sweep from left to right, record a value of temp as the right boundary of the current interval, if the left boundary of the next interval is greater than temp, the result is added one, update to the next point, if the right edge of the next interval is less than temp, so that temp equals the next interval right boundary.

AC Code

/********************************************problem:1328user:memory:688ktime:16mslanguage:g++result:accepted* /#include <iostream> #include <stdio.h> #include <    Algorithm> #include <math.h>using namespace std;const int n = 1005;int N, d;struct point {double x, y;    BOOL operator < (const point a) const {return x < a.x;    }} P[n];int solve () {int i;     Sort (p, p + N);/for (i = 0; i < n; ++i) {//printf ("%d:%f,%f\n", I, p[i].x, p[i].y);/} int ans = 1;    Double temp = p[0].y;            for (i = 1; i < n; ++i) {if (p[i].x > Temp) {++ans;        temp = P[I].Y;        } else if (P[i].y < temp) {temp = P[I].Y; }} return ans;    int main () {int I, j = 1;        while (scanf ("%d%d", &n, &d)! = EOF) {if (n = = 0 && D = = 0) break;        int flag = 0;        int x, y;      for (i = 0; i < n; ++i) {      scanf ("%d%d", &x, &y);            if (Y > D) flag = 1;            p[i].x = X-sqrt ((double) d * d-y * y);        P[I].Y = x + sqrt ((double) d * d-y * y);    } printf ("Case%d:%d\n", J + +, Flag -1:solve ()); } return 0;}

  

In the discuss district found a big God big data:

2 5-3 4-6 34 5-5 3-3 52 33 320 8-20 7-18 6-5 8-21 8-15 7-17 5-1 5-2 3-9 61 22 33 44 55 66 77 88 79 610 50 02 30 22 32 30 2 1 33 31 2-3 22 48 52 4-4 4-3 3-3 1-3 0-1 00 56 03 01 2-3 12 13 21 2-3 12 11 20 22 30 22 34-54 34 32 36-93-31 2-3 22 16 21 21 21 2-3 12 10 01 20 22 30 21 33 101 102 34 53 51 102 34 54 71 102 34 50 03 91 102 34 50 0================ Results Case 1:1c ASE 2:2case 3:4case 4:1case 5:1case 6: -1case 7:3case 8: -1case 9:2case 10:1case 11:1case: -1case: -1Case 14 : 2Case 15:1case 16:1case 17:1case: -1case: -1case 20:1

POJ 1328 Radar Installation

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.