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;
}