拯救007(无图模式)

博客内容提及把鳄鱼位置存于结构数组,涉及信息技术中数据结构里数组的应用。
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct Location {
	int x;
	int y;
};
bool Visited[100];
int MaxDistance;
int N;
bool DFS(int Point, struct Location* L);
bool JudgeLive(Location a1);
bool JudgeJump(Location a1, Location a2);
bool JudgeCircle(Location a1);
int main()
{

	scanf("%d %d", &N, &MaxDistance);
	struct Location* L = (struct Location*)malloc(sizeof(struct Location) * N);
	bool flag = false;
	for (int i = 0; i < N; i++)
	{
		scanf("%d %d", &L[i].x, &L[i].y);
	}
	for (int i = 0; i < N; i++)
	{
		if (Visited[i] == false&&JudgeCircle(L[i]))
		{
			flag = DFS(i, L);
			if (flag == true)
			{
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
}
bool JudgeJump(Location a1, Location a2)
{
	return (pow(a1.x - a2.x, 2) + pow(a1.y - a2.y, 2) <= pow(MaxDistance, 2));
}
bool JudgeLive(Location a1)
{
	return(abs(50 - a1.x) <= MaxDistance || abs(-50 - a1.x) <= MaxDistance || abs(50 - a1.y) <= MaxDistance || abs(-50 - a1.y) <= MaxDistance);
}
bool DFS(int Point, struct Location* L)
{
	bool Judge=false;
	Visited[Point] = true;
	if (JudgeLive(L[Point]))
		Judge = true;
	else
	{
		for (int j =0;j < N; j++)
		{
			if (Visited[j]==false&&JudgeJump(L[Point], L[j]))
			{
				Judge = DFS(j, L);
				if (Judge == true)
					break;
			}
		}
	}
	return Judge;
}
bool JudgeCircle(Location a1)
{
	return(pow(a1.x, 2) + pow(a1.y, 2) <= pow(MaxDistance + 7.5, 2));
}

就是把鳄鱼位置放在结构数组里

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值