Peking University 1328 questions

Source: Internet
Author: User
Tags radar

Question link: http://acm.pku.edu.cn/JudgeOnline/problem? Id = 1328

The specific problems to be solved are:

1. Locate the valid range of radar that can radiate to the island based on the location of each island.

2. If multiple zones have a public part, you only need to put the radar in this public area to radiate to all these islands.

3. According to the result of 1 and the theory of 2, we need to find as few public intervals as possible so that each public interval involves the largest number of islands. This process uses greedy strategies.

# Include <iostream>
# Include <cmath>
# Include <algorithm>
Using namespace STD;

# Deprecision MAX 1000

Struct range
{
Double left;
Double right;
};

Bool PRED (range R1, range R2)
{
Return r1.left <r2.left;
}

Int main ()
{
// Freopen ("in.txt", "r", stdin );

Range R [Max];
Int I, j, X, Y, N, D, res, test;
Double TMP;
Bool flag;
Test = 1;
While (CIN> N> D)
{
If (n = 0 & D = 0)
Break;

Cout <"case" <test <":";
++ Test;

Flag = true;
For (I = 0; I <n; ++ I)
{
Cin> x> Y;
If (flag & D> = y)
{
TMP = SQRT (D * D-y * y );
R [I]. Left = x-TMP;
R [I]. Right = x + TMP;
}
Else
{
Flag = false;
Continue;
}
}
If (! Flag)
Cout <-1 <Endl;
Else
{
Sort (R, R + N, Pred );
Res = 1;
For (I = 1, j = 0; I <n; ++ I)
{
If (R [I]. Left> r [J]. Right)
{
++ Res;
J = I;
}
Else
{
If (R [I]. Right <R [J]. Right)
J = I;
}
}
Cout <res <Endl;
}
}
Return 0;
}

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.