拯救007成功,不知道我能不能拯救我自己

距离计算最后使用的是平方,如果两个点之间距离小于007能跳的距离就有边相连
节点的datatype为鳄鱼是否能上岸,使用BFS进行遍历,先去能去的鳄鱼身上
每到一个鳄鱼身上就判断一下能不能成功

其实时间空间造成了浪费,因为我走了007的去的每个鳄鱼,然而走到可以上岸的鳄鱼停就行,但我不知道怎么停

其实这道题一开始没思路,只是慢慢分析最后找到了思路.看来我如果耐得住心思也挺强

等下去了解一下什么是贪心算法
This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape -- he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head... Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).

Assume that the lake is a 100 by 100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him whether or not he can escape.

Input Specification:

Each input file contains one test case. Each case starts with a line containing two positive integers N (≤100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x,y) location of a crocodile. Note that no two crocodiles are staying at the same position.

Output Specification:

For each test case, print in a line "Yes" if James can escape, or "No" if not.

Sample Input 1:

14 20
25 -15
-25 28
8 49
29 15
-35 -2
5 28
27 -29
-8 -28
-20 -35
-25 -20
-13 29
-30 15
-35 40
12 12

Sample Output 1:

Yes

Sample Input 2:

4 13
-12 12
12 12
-12 -12
12 -12

Sample Output 2:

No

 

/*此题:距离计算最后使用的是平方,如果两个点之间距离小于007能跳的距离就有边相连
节点的datatype为鳄鱼是否能上岸,使用BFS进行遍历,先去能去的鳄鱼身上
每到一个鳄鱼身上就判断一下能不能成功.*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int Flag=0;
#define TRUE 1
#define FALSE 0
typedef struct GNode* PtrToGNode;
typedef struct ENode* PtrToENode;

typedef int Vertex;
typedef int WeightType;
typedef char DataType;
struct Coordinate {
	int x;
	int y;
};
struct GNode {
	int Nv;
	int Ne;
	WeightType** G;//二维矩阵,元素为边的权重,若为无向图则权重为1
	DataType* Data;
	struct Coordinate* Coordinate;
};

typedef PtrToENode Edge;
typedef PtrToGNode MyGraph;
MyGraph CreateGraph(int VertexNum);
MyGraph Build_Graph(int VertexNum, int Length);
_Bool Visited[100];
void DFS(MyGraph Grapth, Vertex V);
void UnconnectedDFS(MyGraph Graph, int Length);
int min4(int a, int b, int c, int d);
int main()
{
	int VertexNum, Length;
	scanf("%d %d", &VertexNum, &Length);
	MyGraph a = Build_Graph(VertexNum,Length);
	UnconnectedDFS(a, Length);
	if (Flag == 1)
		printf("Yes");
	else
		printf("No");


}
MyGraph CreateGraph(int VertexNum)//创建一个图并将邻接矩阵所有节点都初始化为0
{
	MyGraph a = (MyGraph)malloc(sizeof(struct GNode));
	a->G = (WeightType**)malloc(sizeof(WeightType*) * VertexNum);//G是一个指向指针的指针
	for (int i = 0; i < VertexNum; i++)
	{
		a->G[i] = (WeightType*)malloc(sizeof(WeightType) * VertexNum);//a->G[i]是一个指向int的指针
	}
	for (int i = 0; i < VertexNum; i++)
	{
		for (int j = 0; j < VertexNum; j++)
		{
			a->G[i][j] = 0;
		}
	}
	a->Data = (DataType*)malloc(sizeof(DataType) * VertexNum);
	a->Nv = VertexNum;
	a->Ne = 0;
	return a;
}

MyGraph Build_Graph(int VertexNum,int Length)
{
	MyGraph Graph = CreateGraph(VertexNum);
	int Distance;
	int Up, Down, Left, Right;
	Graph->Coordinate = (struct Coordinate*)malloc(sizeof(struct Coordinate) * VertexNum);
	for (int i = 0; i < VertexNum; i++)
	{
		scanf("%d %d", &Graph->Coordinate[i].x, &Graph->Coordinate[i].y);
	}
	for (int i = 0; i < VertexNum; i++)//距离小于等于长度的连通
	{
		for (int j = i + 1; j < VertexNum; j++)
		{
			Distance = pow(Graph->Coordinate[i].x - Graph->Coordinate[j].x, 2) + pow(Graph->Coordinate[i].y - Graph->Coordinate[j].y, 2);//距离计算
			if (Distance <=pow(Length,2))
			{
				Graph->G[i][j] = 1;
				Graph->G[j][i] = 1;

			}
		}
	}
	for (int i = 0; i < VertexNum; i++)//判断每只鳄鱼能否让007上岸
	{
		Up = abs(50 - Graph->Coordinate[i].y);
		Down = abs(-50 - Graph->Coordinate[i].y);
		Left = abs(-50 - Graph->Coordinate[i].x);
		Right = abs(50 - Graph->Coordinate[i].x);
		if (min4(Up, Down, Left, Right) <= Length)
			Graph->Data[i] = 1;
		else
			Graph->Data[i] = 0;

	}
	return Graph;

}

void DFS(MyGraph Graph, Vertex V)
{

	Visited[V] = TRUE;
	if (Graph->Data[V] == 1)
	{
		Flag = 1;
	}

	for (int i = 0; i < Graph->Nv; i++)
	{
			if (Graph->G[V][i] == 1 && Visited[i] == FALSE)
				DFS(Graph, i);
	}


}


void UnconnectedDFS(MyGraph Graph,int Length)
{
	for(int j=0;j<Graph->Nv;j++)
	{
		if ( ((pow(Graph->Coordinate[j].x,2)+pow(Graph->Coordinate[j].y, 2))<pow(Length+7.5,2))&&Visited[j] == FALSE)
		{

			DFS(Graph, j);


		}
	}
}
int min4(int a, int b, int c, int d)
{
	if (a > b)
		a = b;
	if (c > d)
		c = d;
	if (a > c)
		a = c;
	return a;

}

 

 

 

 

 

 

电子时钟设计是一个基于单片机的综合性电子项目,涵盖硬件设计、软件设计、模块代码编写以及运行展示等多个环节。以下是该项目的详细分析与知识点总结: 电子时钟设计是一项课程设计任务,目标是开发一个功能完善的电子时钟系统。该系统以单片机为核心控制器,具备时间显示、设置和控制等功能,旨在满足用户的日常使用需求。 硬件设计的核心是系统方案原理图,它明确了系统的整体架构以及各组件之间的连接关系。外设设计方面,键盘输入模块和数码管显示模块是关键部分。键盘输入模块的工作原理包括键盘扫描、按键识别以及状态机控制等环节;数码管显示模块的工作原理则涉及数码管的驱动、显示控制和状态机控制等内容。 软件设计的核心是项目软件系统总架构图,它详细介绍了系统的软件框架,涵盖单片机编程、键盘输入模块流程图与代码、数码管显示模块流程图与代码等方面。顺序图则展示了软件的运行流程,包括系统初始化、键盘输入处理、显示控制和状态机控制等环节。 模块代码是系统各模块功能的具体实现。例如,键盘输入模块的代码实现了键盘扫描、按键识别和状态机控制等功能;数码管显示模块的代码实现了数码管驱动、显示控制和状态机控制等功能。 运行展示是项目的最终成果呈现环节,展示了电子时钟的实际运行效果,包括时间的准确显示、便捷的设置操作以及稳定的控制功能等。 单片机原理:掌握单片机的架构、指令系统和编程方法。 Proteus仿真:熟悉Proteus仿真原理、仿真环境及仿真操作。 C语言编程:理解C语言的语法、数据类型、控制结构、函数和数组等基础知识。 电子时钟设计:了解电子时钟的工作原理、设计方法和实现技术。 硬件设计:掌握硬件设计的基本原理、方法和工具。 软件设计:熟悉软件设计的基本原理、方法和工具。 模块代码实现:掌握模块代码的设计、编程和调试技巧。 电子时钟设计项目融合了硬件与软件设计,通过模块代码实现功能,并通过运行展示呈现最终效果。掌握
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值