Alien supply station
Time Limit: 2 Seconds Memory Limit: 512 MB
Description
Aliens refer to smart life beyond the Earth. It doesn't matter whether aliens are as long as people on Earth, but at least it should be in line with our current understanding of the basic forms of life. For example, any life we know is inseparable from liquid water, and is a complex organism composed of organic molecules based on the chemical element carbon (C.
Dr. Kong, 42, has been persistently observing the planet ZDM-777 for more than a decade. The red planet called the "God of War" is so fascinating to him. He has made some exciting discoveries over the past decade. The surface of the ZDM-777 planet has significant changes in light and shade, and Dr. Kong has carefully studied these areas for many years and has drawn more detailed maps. He believes that the hidden areas are land, while the bright areas are lakes and oceans. He has always believed that there must be traces of life where there is water. Dr. Kong had a strong hunch that today would be the most memorable day of his life.
This evening's observation conditions were really unprecedented, and the planet ZDM-777 was also very bright, showing a clear dark red circle spot in the radio telescope. Still those familiar areas of light and shade and the Crown, but wait, Dr. Kong seems to have caught what he once saw. What is that. He raised his eyes as much as possible and carefully recognized them. Oh, that's right. On a straight line, several Aurora points are connected to the bright area of the planet. A few minutes later, the Aurora point disappears.
Dr. Kong boldly guessed that there must be creatures in the lakes and oceans on the ZDM-777 planet. Those Aurora points are supply stations on the planet of ZDM-777, regularly offering them life-saving supplies.
It may be set that the line is the x axis, and the Aurora point is on the x axis, with N bright areas P1, P2 ,... Pn is distributed around several Aurora points.
Then Dr. Kong was surprised to find that all the bright area Pi was in the Aurora circle with a radius of R. If you remove an Aurora spot, some bright area Pj will not be in the coverage area.
Dr. Kong wants to know how many Aurora points need to cover all lakes and oceans.
2 ≤ K ≤ 5 1 ≤ R ≤ 50 1 ≤ N ≤ 100-100 ≤ Roxy PYi ≤ 100 | PYi | ≤ R
R and PXi PYi are all integers. There is a space between data.
Input
> Row 1: K indicates the number of groups of test data.
Next, we will test each group of data:
Row 3: N R
2nd ~ N + 1 rows: PXi PYi (I = 1 ,....., N)
Output
For each group of test data, one line is output: the minimum number of Aurora points required.
Sample Input
23 21 2-3 12 11 55 5
Sample Output
21
Source
Henan Sixth College student program design competition
It seems like you have never known each other!
Simple and greedy !!
Sort the positions of the leftmost pole corresponding to each vertex in ascending order, and scan them again to find a greedy strategy!
AC code:
# Include <cstdio> # include <iostream> # include <cstring> # include <cstdlib> # include <cmath> # include <stack> # include <queue> # include <algorithm> # include <string> using namespace std; struct fun {double zuo, you;} a [110]; bool cmp (fun a, fun B) {return. zuo <B. zuo;} int main () {int K, N; double R; scanf ("% d", & K); while (K --) {double x, y; scanf ("% d % lf", & N, & R); for (int I = 0; I <N; I ++) {scanf ("% lf", & x, & y); a [I]. zuo = x-sqrt (R * R-y * y); a [I]. you = x + sqrt (R * R-y * y);} sort (a, a + N, cmp); int ans = 1; double k = a [0]. you; for (int I = 1; I <N; I ++) {if (a [I]. you <= k) k = a [I]. you; else if (a [I]. zuo> k) {ans ++; k = a [I]. you ;}} printf ("% d \ n", ans);} return 0 ;}
Program design competition for the sixth college student in Henan province-the supply station of aliens