Safest Buildings(ZOJ)

                                               Safest Buildings

PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for weapons and equipment to kill others while avoiding getting killed themselves. BaoBao is a big fan of the game, but this time he is having some trouble selecting the safest building.

There are buildings scattering on the island in the game, and we consider these buildings as points on a two-dimensional plane. At the beginning of each round, a circular safe area whose center is located at (0, 0) with radius will be spawned on the island. After some time, the safe area will shrink down towards a random circle with radius (). The whole new safe area is entirely contained in the original safe area (may be tangent to the original safe area), and the center of the new safe area is uniformly chosen within the original safe area.

The buildings covered by the new safe area is called the safe buildings. Given the radius of the safe areas and the positions of the buildings, BaoBao wants to find all the buildings with the largest probability to become safe buildings.

Input

There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:

The first line contains three integers (), and (), indicating the number of buildings and the radius of two safe circles.

The following lines each contains 2 integers and (), indicating the coordinate of the buildings. Here we assume that the center of the original safe circle is located at , and all the buildings are inside the original circle.

It's guaranteed that the sum of over all test cases will not exceed 5000.

Output

For each test case output two lines.

The first line contains an integer , indicating the number of buildings with the highest probability to become safe buildings.

The second line contains integers separated by a space in ascending order, indicating the indices of safest buildings.

Please, DO NOT output extra spaces at the end of each line.

Sample Input

2
3 10 5
3 4
3 5
3 6
3 10 4
-7 -6
4 5
5 4

Sample Output

1
1
2
2 3

题目链接:

https://vjudge.net/problem/ZOJ-3993

题意描述:

给你n个坐标两个圆,半径分别为R和r,然后问在半径为r圆内概率最大的点,并输出点的个数和这些点是第几个点。

解题思路:

用一个结构体存这些点和它们到原点的距离,然后判断最小点点到原点的距离和R-2*r的大小,如果t小于R-2*r就把小于等于R-2*r的点全部输出,否则只输出离原点最近的点即可。

程序代码:

#include<stdio.h>
#include<algorithm>
using namespace std;
#define inf 99999999
struct data{
	int x;
	int y;
	int d;
	int flag;
}a[110];
int main()
{
	int T,i,j,n,R,r,t,temp,count;
	scanf("%d",&T);
	while(T--)
	{
		t=inf;
		count=0;
		scanf("%d%d%d",&n,&R,&r);
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&a[i].x,&a[i].y);
			a[i].d=a[i].x*a[i].x+a[i].y*a[i].y;
			t=min(t,a[i].d);
		}
		temp=(R-2*r)*(R-2*r);
		if(t<=temp)
		{
			for(i=1;i<=n;i++)
				if(a[i].d<=temp)
					a[count++].flag=i;
		}	
		else
		{
			for(i=1;i<=n;i++)
				if(a[i].d==t)
					a[count++].flag=i;
		}
		printf("%d\n",count);
		for(i=0;i<count;i++)
		{
			printf("%d",a[i].flag);
			if(i==count-1)
				printf("\n");
			else
				printf(" ");
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/HeZhiYing_/article/details/83502500
ZOJ