5-10 Saving James Bond - Easy Version (25分)

#include <iostream>
#include <math.h>

using namespace std;

struct node
{
	int x, y, flag;
}vis[110];

int flag, d, n;

double getdis(int index0, int index1)
{
	return sqrt(((vis[index0].x - vis[index1].x) * (vis[index0].x - vis[index1].x) + (vis[index0].y - vis[index1].y) * (vis[index0].y - vis[index1].y)) * 1.0);
}

void dfs(int curindex)
{
	if(abs(vis[curindex].x) + d >= 50 || abs(vis[curindex].y) + d >= 50)
	{
		flag = 1;
		return;
	}

	int i;
	for(i = 1; i <= n && flag == 0; i++)
	{
		if(vis[i].flag == 0 && getdis(curindex, i) <= d)
		{
			vis[i].flag = 1;
			dfs(i);
		}
	}
}

int main()
{
	scanf("%d%d", &n, &d);

	int i, x, y;
	node nod;

	for(i = 1; i <= n; i++)
	{
		scanf("%d%d", &vis[i].x, &vis[i].y);
		vis[i].flag = 0;
	}

	if(7.5 + d >= 50)
	{
		printf("Yes\n");
		return 0;
	}

	vis[0].x = vis[0].y = 0;
	for(i = 1; i <= n && flag == 0; i++)
	{
		if(vis[i].flag == 0 && getdis(0, i) <= d + 7.5)
		{
			vis[i].flag = 1;
			dfs(i);
		}
	}

	if(flag == 1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	system("pause");
	return 0;
}

 

posted on 2025-11-29 14:59  王景迁  阅读(1)  评论(0)    收藏  举报

导航