The sixth College Students' Program Design Competition in Henan province-the supply station of aliens and the Design Competition in Henan Province

Source: Internet
Author: User

The sixth College Students' Program Design Competition in Henan province-the supply station of aliens and the Design Competition in Henan Province

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 a.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 %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;}





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.