nyoj 710 Alien Supply Station

Alien supply station

Time Limit: 1000 ms | Memory Limit: 65535 KB

Difficulty: 3

describe

Aliens refers to intelligent life beyond Earth. It doesn't matter whether the aliens are the same size as people on Earth, but at least it should be in line with our current understanding of the basic form of life. For example, any life we ​​know of is inseparable from liquid water and is a complex organism based on the combination of organic molecules of the chemical element carbon ( C ).

The 42 -year-old astronomer Dr. Kong has been obsessively observing the planet ZDM-777 for more than a decade, and the red planet known as " God of War " has fascinated him so much. Over the past decade or so, he has often made some exciting discoveries. The surface of the ZDM-777 planet has obvious light and dark changes. Dr. Kong has carefully studied these light and dark areas for many years, and has drawn a relatively detailed map. He firmly believed that the dark areas were land, and the bright areas were lakes and oceans. He has always believed that where there is water, there must be traces of life. Dr. Kong has a strong feeling that today will be the most memorable day of his life.
    The observation conditions that night were really unprecedented, and the planet ZDM-777 was also very bright, showing a clear dark red spot in the radio telescope. It's still those familiar light and dark areas and polar crowns, but wait, Dr. Kong seems to have caught what he's seen before, what is it, looming. He opened his eyes as wide as he could, identifying carefully. Oh, yes, in a straight line, several aurora points appeared to connect the bright areas of the planet. After a few minutes, the aurora points disappeared.

Dr. Kong boldly guessed that there must be creatures in the lakes and oceans on the planet ZDM-777. Those aurora spots are the supply stations on the planet ZDM-777, regularly providing these creatures with life-sustaining supplies.

It may be assumed that the straight line is the X- axis, the aurora points are located on the X- axis, and the N bright areas P1, P2, ... Pn are distributed around several aurora points.

 

Then, Dr. Kong made a surprising discovery that all the bright areas Pi are within a circle of auroral points with a radius of R. Removing an aurora point will result in some bright areas Pj that are not in the coverage area.

Dr. Kong wondered how many aurora spots would be needed to cover all the lakes and oceans.

enter

First line: K indicates how many sets of test data there are. 
Next, for each set of test data:
Line 1: NR
Line 2~N+1: PXi PYi (i=1,…..,N)

[Constraints]
2≤K≤5 1≤R≤50 1≤ N≤100 -100≤PXi PYi≤100 | PYi | ≤ R 
R, PXi PYi are all integers. There is a space between the data.

output

For each set of test data, output one line: the minimum required number of aurora points.

sample input

2

3 2

1 2

-3 1

2 1

1 5

5 5

Sample output

2

1

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

struct point{
	double left; //left intersection
	double right; //Right intersection
}w[1001];

bool cmp(const point a,const point b)
{
	if(a.left<b.left)
		return true;
	return false;
}

intmain()
{
	int t,n,r,x,y;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&r);
			memset(w,0,sizeof(w));
			int count=1; //counter
			double len,t;
			
			for(int i=0;i<n;i++)
			{
				scanf("%d%d",&x,&y);
//				if(y>r)
//				{
//					//printf("-1\n");
//					break;
//				}
//				
				len=sqrt(((double)r*r)-((double)y*y)); //Pythagorean theorem
				w[i].left=(double)x-len;
				w[i].right=(double)x+len;
			}
			
			sort(w,w+n,cmp);
			t=w[0].right;
			for(int i=1;i<n;i++)
			{
				if(w[i].left>t)//**If the left intersection of the next point is greater than the right coordinate of the previous point,
									//Indicate that there is no common area for two points
				{
					count++;
					t=w[i].right;
				}
				else
				{
					if(w[i].right<t)//**If the right intersection of the next point is less than the right coordinate of the previous point,
									//Indicate that the coverage area of ​​the next point is included by the previous point**//
					{
						t=w[i].right;//** Ensure that the latter point is covered
					}
				}
			}
			printf("%d\n",count);
	}	
	return 0;
}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324654245&siteId=291194637