浙大数据结构第六周之初识图

题目详情:06-图1 列出连通集

给定一个有N个顶点和E条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。

输入格式:

输入第1行给出2个整数N(0<N≤10)和E,分别是图的顶点数和边数。随后E行,每行给出一条边的两个端点。每行中的数字之间用1空格分隔。

输出格式:

按照"{ v1​ v2​ ... vk​ }"的格式,每行输出一个连通集。先输出DFS的结果,再输出BFS的结果。

输入样例:

8 6
0 7
0 1
2 0
4 1
2 4
3 5

输出样例:

{ 0 1 4 2 7 }
{ 3 5 }
{ 6 }
{ 0 1 2 7 4 }
{ 3 5 }
{ 6 }

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

主要思路:

三个重要模块:

(一)图的存储

这次尝试的是用二维邻接矩阵,以后有机会尝试一位邻接矩阵和邻接表

二维邻接矩阵关键四步:

(1)定义图的数据结构,分为图节点与边节点两部分

/*图节点*/
typedef struct GraphNode* PToGraphNode;
struct GraphNode {
    int VertexNums;
    int EdgeNums;
    int WeightBetweenTwoEdge[MAX_SIZE][MAX_SIZE];
};
typedef PToGraphNode MatrixGraph;
/*边界点*/
typedef struct EdgeNode* PToEdgeNode;
struct EdgeNode {
    int Start, End;
    int Weight;
};
typedef PToEdgeNode Edge;

(2)创建一个没有边的图

MatrixGraph CreateGraph() {
    int vertixNums;
    scanf("%d", &vertixNums);

    MatrixGraph Graph = (MatrixGraph)malloc(sizeof(struct GraphNode));
    Graph -> VertexNums = vertixNums;
    Graph -> EdgeNums = 0;
    for(int i = 0; i < (Graph -> VertexNums); i++) {
        for(int j = 0; j < (Graph -> VertexNums); j++) {
            Graph -> WeightBetweenTwoEdge[i][j] = 0;
        }
    }
    return Graph;
}

 (3)插入边

void InsertEdge(MatrixGraph graph, Edge edge) {
    graph -> WeightBetweenTwoEdge[edge -> Start][edge -> End] = edge -> Weight;
    graph -> WeightBetweenTwoEdge[edge -> End][edge -> Start] = edge -> Weight;
}

(4)创建图

MatrixGraph BuildGraph() {
    MatrixGraph graph = CreateGraph();
    scanf("%d", &(graph -> EdgeNums));
    if((graph -> EdgeNums) != 0) {
        for(int i = 0; i < (graph -> EdgeNums); i++) {
            Edge edge = (Edge)malloc(sizeof(struct EdgeNode));
            scanf("%d %d", &(edge -> Start), &(edge -> End));
            edge -> Weight = WEIGHT; 
            InsertEdge(graph, edge); 
        }
    }
    return graph;
}

(二)DFS的实现

关于图的DFS 有常规思路如下:

void DFS(u) {
  vis[u] = true;	// 设置为已访问
  Visit[u]           //访问节点
  for(从u出发能达到的所有顶点v)	// 枚举从u出发可以到达的所有顶点
    	if vis[v] == false	// 没有被访问
        	DFS(v)	// 递归访问
}

void DFSTravel(G) {
  for(G所有顶点u)
    if vis[u] == false
      DFS(u)
}

(三)BFS的实现 

BFS常规思路

void BFS(int u) {
  queue q;
  q.push(u);
  inq[u] = true;	// 设置 u 已经入队
  while(!q.empty()) {
    Visit[q.front()]        //取出队首元素进行访问
    for(从u出发可到达所有顶点v)
      	if(inq[v] == false)
          将 v 入队
          inq[v] = true
  }
}

void BFSTravel() {
  for(G所有顶点u) {
    if(inq[u] == false)
      	BFS(u)
  }
}

代码实现:

#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 11
#define WEIGHT 1
/*用邻接矩阵定义图的数据结构*/
/*图节点*/
typedef struct GraphNode* PToGraphNode;
struct GraphNode {
    int VertexNums;
    int EdgeNums;
    int WeightBetweenTwoEdge[MAX_SIZE][MAX_SIZE];
};
typedef PToGraphNode MatrixGraph;
/*边界点*/
typedef struct EdgeNode* PToEdgeNode;
struct EdgeNode {
    int Start, End;
    int Weight;
};
typedef PToEdgeNode Edge;
/*---------------------------*/
/*初始化一个无边的图*/
MatrixGraph CreateGraph() {
    int vertixNums;
    scanf("%d", &vertixNums);

    MatrixGraph Graph = (MatrixGraph)malloc(sizeof(struct GraphNode));
    Graph -> VertexNums = vertixNums;
    Graph -> EdgeNums = 0;
    for(int i = 0; i < (Graph -> VertexNums); i++) {
        for(int j = 0; j < (Graph -> VertexNums); j++) {
            Graph -> WeightBetweenTwoEdge[i][j] = 0;
        }
    }
    return Graph;
}
/*边的插入*/
void InsertEdge(MatrixGraph graph, Edge edge) {
    graph -> WeightBetweenTwoEdge[edge -> Start][edge -> End] = edge -> Weight;
    graph -> WeightBetweenTwoEdge[edge -> End][edge -> Start] = edge -> Weight;
}
/*创建图*/
MatrixGraph BuildGraph() {
    MatrixGraph graph = CreateGraph();
    scanf("%d", &(graph -> EdgeNums));
    if((graph -> EdgeNums) != 0) {
        for(int i = 0; i < (graph -> EdgeNums); i++) {
            Edge edge = (Edge)malloc(sizeof(struct EdgeNode));
            scanf("%d %d", &(edge -> Start), &(edge -> End));
            edge -> Weight = WEIGHT; 
            InsertEdge(graph, edge); 
        }
    }
    return graph;
}
int Visited[MAX_SIZE];
void DFS(MatrixGraph graph, int index) {
    Visited[index] = 1;
    printf("%d ", index);
    /*遍历当下节点(下标为index)所有相邻节点*/
    for(int i = 0; i < (graph -> VertexNums); i++) {
        /*判断当下节点的相邻节点,两个节点间连通且相邻的节点没有访问过*/
        if(graph -> WeightBetweenTwoEdge[index][i] == WEIGHT && Visited[i] == 0) {
            Visited[i] = 1;
            DFS(graph, i);
        }
    }
    return;
}
void Erase(int* array, int num) {
    for(int i = 0; i < num; i++) {
        array[i] = 0;
    }
    return;
}
/*先实现循环队列*/
#define MAX_QUEUE_SIZE 10
 
typedef struct {
    int data[MAX_QUEUE_SIZE];
    int front;
    int rear;
    int count;
} CircularQueue;
 
void initialize_queue(CircularQueue* queue) {
    queue->front = 0;
    queue->rear = -1;
    queue->count = 0;
}
 
int is_full(CircularQueue* queue) {
    return (queue->count == MAX_QUEUE_SIZE);
}
 
int is_empty(CircularQueue* queue) {
    return (queue->count == 0);
}
 
int enqueue(CircularQueue* queue, int data) {
    if(is_full(queue)) {
        return 0;
    }
    queue->rear = (queue->rear + 1) % MAX_QUEUE_SIZE;    //因为是循环,所以不是简单加1,还要取余
    queue->data[queue->rear] = data;
    (queue->count)++;
    return 1;
}
 
int dequeue(CircularQueue* queue) {
    if(is_empty(queue)) {
        return -1;
    }
    int data = queue->data[queue->front];
    queue->front = (queue->front + 1) % MAX_QUEUE_SIZE;
    queue->count--;
    return data;
}
void BFS(MatrixGraph graph, int index) {
    CircularQueue queue;
    initialize_queue(&queue);
    
    Visited[index] = 1;
    enqueue(&queue, index);

    while(!is_empty(&queue)) {
        index = dequeue(&queue);
        printf("%d ", index);
        for(int i = 0; i < (graph -> VertexNums); i++) {
            if(Visited[i] == 0 && graph -> WeightBetweenTwoEdge[index][i] == WEIGHT) {
                Visited[i] = 1;
                enqueue(&queue, i);
            }
        }
    }
}
int main() {
    MatrixGraph graph = BuildGraph();
    for(int i = 0; i < (graph -> VertexNums); i++) {
        if(Visited[i] == 0) {   //表示一个连通集的开始
            printf("{ ");
            DFS(graph, i);
            printf("}\n");
        }
    }
    Erase(Visited, MAX_SIZE);
    for(int i = 0; i < (graph -> VertexNums); i++) {
        if(Visited[i] == 0) {
            printf("{ ");
            BFS(graph, i);
            printf("}\n");
        }
    }
    return 0;
}

题目详情:06-图2 Saving James Bond - Easy Version

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

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

简单翻译:

就是在以所给的最远跳跃距离为半径这个限制,看能不能找到一条从湖心到湖岸的路径

主要思路:

(一)利用图,将人,鳄鱼和岸都视为节点,分为第一跳,中间跳与最后跳上岸三种情况,如果满足,只要满足限制条件就在两个节点之间插入边,然后利用DFS遍历图看有无路径即可

虽然但是,还是有一个测试点过不了……先贴在这边,看看以后能不能看出问题

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_SIZE 101
#define WEIGHT 1
#define ISLANDRADIUS 7.5
#define BOUND 50
typedef struct GraphNode* PToGraphNode;
struct GraphNode {
    int VertexNums;
    int EdgeNums;
    int WeightBetweenTwoNodes[MAX_SIZE][MAX_SIZE];
};
typedef PToGraphNode MatrixGraph;
typedef struct EdgeNode* PToEdgeNode;
struct EdgeNode {
    int Start, End;
    int Weight;
};
typedef PToEdgeNode Edge;
MatrixGraph CreateEmptyGraph(int vertexNums) {
    MatrixGraph graph = (MatrixGraph)malloc(sizeof(struct GraphNode));
    graph -> VertexNums = vertexNums;
    graph -> EdgeNums = 0;
    for(int i = 0; i < (graph -> VertexNums); i++) {
        for(int j = 0; j < (graph -> VertexNums); j++) {
            graph -> WeightBetweenTwoNodes[i][j] = 0;
        }
    }    
    return graph;
}
Edge InitalEdge(int start, int end, int weight) {
    Edge edge = (Edge)malloc(sizeof(struct EdgeNode));
    edge -> Start = start;
    edge -> End = end;
    edge -> Weight = weight;
    return edge;
}
void InsertEdge(MatrixGraph graph, Edge edge) {
    int start = edge -> Start;
    int end = edge -> End;
    graph -> WeightBetweenTwoNodes[start][end] = edge -> Weight;
    graph -> WeightBetweenTwoNodes[end][start] = edge -> Weight;
    return;
}
typedef struct VertexNode* PToVettex; 
struct VertexNode {
    int XLabel, Ylabel;
};
typedef PToVettex Vertex;
int Max(int a, int b) {
    return a > b ? a : b;
}
MatrixGraph BuildGraph() {
    int crocodileNums, maxDistance;
    scanf("%d %d", &crocodileNums, &maxDistance);
    MatrixGraph graph = CreateEmptyGraph(crocodileNums + 2);
    Vertex vertex = (Vertex)malloc(sizeof(struct VertexNode) * (crocodileNums + 1));
    //0号节点代表湖心岛,1~vertixNums节点代表鳄鱼
    for(int i = 1; i <= crocodileNums; i++) {
        scanf("%d %d", &(vertex[i].XLabel), &(vertex[i].Ylabel));
    }

    //判断从小岛可以跳到几只鳄鱼背上,如果可以,就在岛代表的节点与鳄鱼代表的节点之间插入一条边
    for(int i = 1; i <= crocodileNums; i++) {
        int distanceSquare = pow(vertex[i].XLabel, 2) + pow(vertex[i].Ylabel, 2);
        if(pow((ISLANDRADIUS + maxDistance), 2) >= distanceSquare) {
            Edge edge = InitalEdge(0, i, WEIGHT);
            InsertEdge(graph, edge);
            free(edge);
        }
    }

    //判断是否可以在两条鳄鱼间跳跃
    for(int i = 1; i <= crocodileNums; i++) {
        int plotStartX = vertex[i].XLabel;
        int plotStartY = vertex[i].Ylabel;
        for(int j = i + 1; j <= crocodileNums; j++) {
            int plotEndX = vertex[j].XLabel;
            int plotEndY = vertex[j].Ylabel;
            int distanceSquare = pow((plotEndX - plotStartX), 2) + pow((plotEndY - plotStartY), 2);
            if(distanceSquare <= pow(maxDistance, 2)) {
                Edge edge = InitalEdge(i, j, WEIGHT);
                InsertEdge(graph, edge);
                free(edge);
            }
        }
    }

    //判断是否可以从鳄鱼跳到岸上
    for(int i = 1; i <= crocodileNums; i++) {
        int absPlotXLabel = abs(vertex[i].XLabel);
        int absPlotYLabel = abs(vertex[i].Ylabel);
        if(absPlotXLabel + maxDistance >= 50 || absPlotYLabel + maxDistance >= 50) {
            Edge edge = InitalEdge(i, crocodileNums + 1, WEIGHT);
            InsertEdge(graph, edge);
            free(edge);
        }    
    }

    return graph;
}
int Visited[MAX_SIZE];
int flag = 0;
void DFS(MatrixGraph graph, int index) {
    Visited[index] = 1;
    if(index == (graph -> VertexNums) - 1) {    //表示岸边的节点的下标是总结点数-1
        flag = 1;
        return;
    }

    for(int i = 1; i < (graph -> VertexNums); i++) {
        if(graph -> WeightBetweenTwoNodes[index][i] == WEIGHT && Visited[i] == 0) {   
            DFS(graph, i);
        }
    }
}
int main() {
    MatrixGraph graph = BuildGraph();
    DFS(graph, 0);
    if(flag == 1) printf("Yes\n");
    else printf("No\n");
    system("pause");
    return 0;
}

贴一下别人正确的代码

#include<stdio.h>
#include<stdbool.h>
#include<math.h>

#define MaxVertexNum 100
#define Diameter 15

typedef int Crocodile;

typedef struct LocOfCro{
    int x;
    int y;
}Location;

int Nc, distance;
bool visited[MaxVertexNum] = { false };
Location crocodiles[MaxVertexNum];

void AddCrocodile();
void Save007(Location Crocodile[]);
int DFS(Crocodile V);
bool IsSafe(Crocodile V);
bool FirstJump(V);
bool Jump(V, W);

int main() {
    AddCrocodile();
    Save007(crocodiles);
    return 0;
}

void AddCrocodile() {
    int v1, v2;
    scanf("%d", &Nc);
    /* CreateLocation */
    for (int i = 0; i < Nc; i++) {
        crocodiles[i].x = crocodiles[i].y = -1;
    }
    scanf("%d", &distance);
    for (int i = 0; i < Nc; i++) {
        scanf("%d %d", &v1, &v2);
        /* AddCrocodile */
        crocodiles[i].x = v1;
        crocodiles[i].y = v2;
    }
}

int DFS(Crocodile i) {
    int answer = 0;
    visited[i] = true;
    if (IsSafe(i))
        answer = 1;
    else {
        for (int j = 0; j < Nc; j++)
            if (!visited[j] && Jump(i,j)) {
                answer = DFS(j);
                if (answer == 1)
                    break;
            }
    }
    return answer;
}

void Save007(Location crocodiles[]) {
    int answer = 0;
    for (int i = 0; i < Nc; i++) {
        if (!visited[i] && FirstJump(i)) {
            answer = DFS(i);
            if (answer == 1) break;
        }
    }
    if (answer == 1) printf("Yes");
    else printf("No");
}

bool IsSafe(Crocodile i) {
    return (abs(crocodiles[i].x) + distance >= 50) || (abs(crocodiles[i].y) + distance >= 50);
}

bool FirstJump(Crocodile i) {
    return sqrt(pow(crocodiles[i].x + 0.0, 2) + pow(crocodiles[i].y + 0.0, 2)) <= (Diameter / 2 + distance);
}

bool Jump(int V, int W) {
    return sqrt((crocodiles[V].x - crocodiles[W].x) * (crocodiles[V].x - crocodiles[W].x)
        + (crocodiles[V].y - crocodiles[W].y) * (crocodiles[V].y - crocodiles[W].y)) <= distance;
}

(二)不用图(有空再想想吧)

题目详情:06-图3 六度空间

“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。

“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。


图1 六度空间示意图

“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标。然而由于历史的原因,这样的研究具有太大的局限性和困难。随着当代人的联络主要依赖于电话、短信、微信以及因特网上即时通信等工具,能够体现社交网络关系的一手数据已经逐渐使得“六度空间”理论的验证成为可能。

假如给你一个社交网络图,请你对每个节点计算符合“六度空间”理论的结点占结点总数的百分比。

输入格式:

输入第1行给出两个正整数,分别表示社交网络图的结点数N(1<N≤103,表示人数)、边数M(≤33×N,表示社交关系数)。随后的M行对应M条边,每行给出一对正整数,分别是该条边直接连通的两个结点的编号(节点从1到N编号)。

输出格式:

对每个结点输出与该结点距离不超过6的结点数占结点总数的百分比,精确到小数点后2位。每个结节点输出一行,格式为“结点编号:(空格)百分比%”。

输入样例:

10 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10

输出样例:

1: 70.00%
2: 80.00%
3: 90.00%
4: 100.00%
5: 100.00%
6: 100.00%
7: 100.00%
8: 90.00%
9: 80.00%
10: 70.00%

代码长度限制

16 KB

时间限制

2500 ms

内存限制

64 MB 

主要思路:

利用BFS搜索,难点在于如何判断最后一个节点从而积累层数,解决方法是要先深刻理解BFS就是拓展层序遍历,弹出的是中心节点,加入的是围绕其的节点,所以分别记录当前层最后一个节点与上一层最后一个节点,当现在的中心节点等于上一层的最后一个节点就说明有一层遍历完了

第一次写错误:

(1)忽视了节点是从1开始编号的

(2)人计数时从1开始,因为当前节点也在内

(3)一开始用DFS,但有问题,具体原因可以参见这篇文章

代码实现:

#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1005
#define WEIGHT 1
typedef struct GraphNode* PToGraphNode;
struct GraphNode {
    int VertexNums;
    int EdgeNums;
    int WeightBetweenTwoNodes[MAX_SIZE][MAX_SIZE];
};
typedef PToGraphNode MatrixGraph;
typedef struct EdgeNode* PToEdgeNode;
struct EdgeNode {
    int Start, End;
    int Weight;
};
typedef PToEdgeNode Edge;
MatrixGraph CreateEmptyGraph(int vertexNums) {
    MatrixGraph graph = (MatrixGraph)malloc(sizeof(struct GraphNode));
    graph -> VertexNums = vertexNums;
    graph -> EdgeNums = 0;
    for(int i = 1; i <= vertexNums; i++) {
        for(int j = 1; j <= vertexNums; j++) {
            graph -> WeightBetweenTwoNodes[i][j] = 0;
        }
    }
    return graph;
}
void InsertEdge(MatrixGraph graph, Edge edge) {
    int start = edge -> Start;
    int end = edge -> End;
    graph -> WeightBetweenTwoNodes[start][end] = edge -> Weight;
    graph -> WeightBetweenTwoNodes[end][start] = edge -> Weight;
    return;
}
MatrixGraph BuildGraph() {
    int vertexNums;
    scanf("%d", &vertexNums);
    MatrixGraph graph = CreateEmptyGraph(vertexNums);
    scanf("%d", &(graph -> EdgeNums));
    for(int i = 1; i <= (graph -> EdgeNums); i++) {
        int start, end;
        scanf("%d %d", &start, &end);
        Edge edge = (Edge)malloc(sizeof(struct EdgeNode));
        edge -> Start = start;
        edge -> End = end;
        edge -> Weight = WEIGHT;
        InsertEdge(graph, edge);
        free(edge);
    }
    return graph;
}
/*先实现循环队列*/
#define MAX_QUEUE_SIZE 1005
 
typedef struct {
    int data[MAX_QUEUE_SIZE];
    int front;
    int rear;
    int count;
} CircularQueue;
 
void initialize_queue(CircularQueue* queue) {
    queue->front = 0;
    queue->rear = -1;
    queue->count = 0;
}
 
int is_full(CircularQueue* queue) {
    return (queue->count == MAX_QUEUE_SIZE);
}
 
int is_empty(CircularQueue* queue) {
    return (queue->count == 0);
}
 
int enqueue(CircularQueue* queue, int data) {
    if(is_full(queue)) {
        return 0;
    }
    queue->rear = (queue->rear + 1) % MAX_QUEUE_SIZE;    //因为是循环,所以不是简单加1,还要取余
    queue->data[queue->rear] = data;
    (queue->count)++;
    return 1;
}
 
int dequeue(CircularQueue* queue) {
    if(is_empty(queue)) {
        return -1;
    }
    int data = queue->data[queue->front];
    queue->front = (queue->front + 1) % MAX_QUEUE_SIZE;
    queue->count--;
    return data;
}

int Visited[MAX_SIZE];
int PeopleInside = 1;
void Clear(int* array, int size) {
    for(int i = 1; i <= size; i++) array[i] = 0;
    return;
}
int peopleInside = 1;
void BFS(MatrixGraph graph, int center) {   //用center命名更符合BFS搜索本质,一个节点为中心将其临近节点全部压入
    CircularQueue myQueue;
    initialize_queue(&myQueue);
    Visited[center] = 1;
    enqueue(&myQueue, center);
    int thisLevelTail = -1;
    int level = 0;
    int lastTail = center;
    while(!is_empty(&myQueue)) {
        center = dequeue(&myQueue);
        for(int i = 1; i <= (graph -> VertexNums); i++) {
            if(Visited[i] == 0 && graph -> WeightBetweenTwoNodes[center][i] == WEIGHT) {
                enqueue(&myQueue, i);
                thisLevelTail = i;   //thisleveltail记录的是这一层的最后一个
                Visited[i] = 1;
                peopleInside++;
            }
        }
        if(center == lastTail) {    //如果这一层中心点到了上一层末尾,说明队列里之后存放就是下一层节点了
            level++;
            lastTail = thisLevelTail;
        }
        if(level == 6) break;
    }
}
int main() {
    MatrixGraph graph = BuildGraph();
    int totalPeople = graph -> VertexNums;
    for(int i = 1; i <= totalPeople; i++) {
        Clear(Visited, totalPeople);
        BFS(graph, i);
        printf("%d: %.2f\%\n", i, 1.0 * peopleInside / (totalPeople) * 100);
        peopleInside = 1;
    }
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/21816.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

飞书接入ChatGPT - 将ChatGPT集成到飞书机器人,直接拉满效率

文章目录 前言环境列表视频教程1.飞书设置2.克隆feishu-chatgpt项目3.配置config.yaml文件4.运行feishu-chatgpt项目5.安装cpolar内网穿透6.固定公网地址7.机器人权限配置8.创建版本9.创建测试企业10. 机器人测试 转载自远控源码文章&#xff1a;飞书接入ChatGPT - 将ChatGPT集…

服务(第二十八篇)rsync

配置rsync源服务器&#xff1a; #建立/etc/rsyncd.conf 配置文件 vim /etc/rsyncd.conf #添加以下配置项 uid root gid root use chroot yes #禁锢在源目录 address 192.168.80.10 …

庄懂的TA笔记(十四十六)<特效:火焰 + 水流>

庄懂的TA笔记&#xff08;十四&十六&#xff09;&#xff1c;特效&#xff1a;火焰 水流&#xff1e; 目录 一、作业展示&#xff1a; 二、示范&#xff1a;火: 参考资料&#xff1a; 实现思路&#xff1a; 实践操作&#xff1a; 三、示范&#xff1a;水: 实现思路&am…

PCB 布线技术~PCB结构:Traces,电源平面

PCB导体:Traces • 铜是PCB中最常用的导体 – 走线或连接器一般通过镀金来提供一个抗腐蚀的电传导特性 – 走线的宽度和长度-由PCB布线工程师控制 • 在通常的制造工艺下&#xff0c;走线的宽度和之间的间距一般要≥5 mil – 走线厚度-制造工艺的变量 • 典型值 0.5oz – 3oz •…

C++(2):变量和基本类型

基本内置类型 C定义了一套包括算术类型&#xff08;arithmetic type&#xff09;和空类型&#xff08;void&#xff09;在内的基本数据类型。其中算术类型包含了字符、整型数、布尔值和浮点数。空类型不对应具体的值。 算数类型 算数类型分为两类&#xff1a;整型&#xff0…

【Linux】多种环境变量介绍与设置

文章目录 一. linux环境变量介绍1. linux中的环境变量配置文件2. 环境变量加载顺序 二. 操作环境变量1. 读取环境变量envexportecho $PATH 2. 设置环境变量2.1. export PATH&#xff1a;临时的环境变量2.2. 用户的环境变量vim ~/.bashrcvim ~/.bash_profile 2.3. 所有用户的环境…

网络原理(四):传输层协议 TCP/UDP

目录 应用层 传输层 udp 协议 端口号 报文长度&#xff08;udp 长度&#xff09; 校验和 TCP 协议 确认应答 超时重传 链接管理 滑动窗口 流量控制 拥塞控制 延时应答 捎带应答 总结 我们第一章让我们对网络有了一个初步认识&#xff0c;第二章和第三章我们通…

SpringBoot 整合 ChatGPT API 项目实战

SpringBoot 整合 ChatGPT API 项目实战 一、准备工作 二、补全接口示例 三、申请API-KEY 四、JavaScript调用API 五、SpringBoot使用ChatGPT API 体验到了ChatGPT的强大之后&#xff0c;那么我们会想&#xff0c;如果我们想基于ChatGPT开发一个自己的聊天机器人&#xff0…

论文、专利、文献检索及图像数据工具总结

一、文献检索 1、中文文献检索参考 中文文献途径网址用途1知网https://www.cnki.net/文献检索、下载2万方数据网https://www.wanfangdata.com.cn/文献检索、下载3维普期刊http://lib.cqvip.com/文献检索、下载4浙江图书馆https://www.zjlib.cn/#searchs_1_div文献检索、下载5…

html监听界面被隐藏或显示

vue相比于小程序和uni-app 显然少了两个有点用的生命周期 onShow 应用被展示 onHide 应用被隐藏 但其实这个 要做其实也很简单 JavaScript中 有对应的visibilitychange事件可以监听 我们Html参考代码如下 <!DOCTYPE html> <html lang"en"> <head>…

8. 机器学习系统设计

假设你想建立一个垃圾邮件分类器&#xff0c;通过监督学习来构造一个分类器来区分垃圾邮件和非垃圾邮件。为了应用监督学习&#xff0c;首先要想的就是&#xff1a;如何来表示邮件的特征向量x&#xff0c;通过特征向量x和分类标签y&#xff0c;我们就能训练一个分类器&#xff…

07-通过RocketMQ和Redis实现用户动态提醒

1、用户动态表 CREATE TABLE `t_user_moments` (`id` bigint(12) unsigned NOT NULL AUTO_INCREMENT COMMENT 主键id,`user_id` bigint(12) DEFAULT NULL COMMENT 用户id,`user_type` int(8) DEFAULT NULL COMMENT 动态类型:0视频 1直播 2专栏动态,`contend_id` bigint(12) D…

Linux下C/C++实现DNS查询(DNS QUERY)

DNS 的全称是 Domain Name System 或者 Domain Name Service&#xff0c;它主要的作用就是将人们所熟悉的网址 (域名) “翻译”成电脑可以理解的 IP 地址&#xff0c;这个过程叫做 DNS 域名解析。域名是由一串用点分隔的名字组成的 Internet 上某一台计算机或计算机组的名称&am…

从裸机启动开始运行一个C++程序(二)

先序文章请看&#xff1a; 从裸机启动开始运行一个C程序&#xff08;一&#xff09; 运行在8086上的第一个程序 既然硬件环境已经就绪了&#xff0c;那接下来&#xff0c;就要想办法让它运行我们的程序了。不过在此之前&#xff0c;我们必须要了解一下8086的主要架构&#xf…

微星MSI GE66 10SF-416RU电脑 Hackintosh 黑苹果efi引导文件

原文来源于黑果魏叔官网&#xff0c;转载需注明出处。&#xff08;下载请直接百度黑果魏叔&#xff09; 硬件配置 硬件型号驱动情况 主板Intel HM470 处理器Intel Core i7-10875H 2.30GHz up to 5.10GHz已驱动 内存Kingston Fury Impact DDR4 2x16Gb 3200mhz已驱动 硬盘NT…

【Linux】权限的理解

&#x1f307;个人主页&#xff1a;平凡的小苏 &#x1f4da;学习格言&#xff1a;命运给你一个低的起点&#xff0c;是想看你精彩的翻盘&#xff0c;而不是让你自甘堕落&#xff0c;脚下的路虽然难走&#xff0c;但我还能走&#xff0c;比起向阳而生&#xff0c;我更想尝试逆风…

Apache Flink 文件上传漏洞 (CVE-2020-17518)

文章目录 一、Apache Flink简介二、漏洞简介三、漏洞复现四、上传jar包getshell 一、Apache Flink简介 Apache Flink 是一个框架和分布式处理引擎&#xff0c;用于在无边界和有边界数据流上进行有状态的计算。Flink 能在所有常见集群环境中运行&#xff0c;并能以内存速度和任…

自定义组件3-behaviors

1、behaviors是小程序中用于实现组件间代码共享的特性&#xff0c;类似于Vue.js中的mixins 2、behaviors的工作方式 每个behaviors可以包含一组属性、数据、生命周期函数和方法。组件引用它时&#xff0c;它的数据和属性和方法会被 合并到组件中。 每个组件可以引用多个behav…

NXP MCUXPresso - cc1plus.exe: out of memory allocating 65536 bytes

文章目录 NXP MCUXPresso - cc1plus.exe: out of memory allocating 65536 bytes概述实验结论补充END NXP MCUXPresso - cc1plus.exe: out of memory allocating 65536 bytes 概述 在尝试迁移 openpnp - Smoothieware project 从gcc命令行 MRI调试方式 到NXP MCUXpresso工程…

数据库界的科技与狠活: 创邻科技Galaxybase X英特尔SGX数据加密解决方案正式发布

引言 近日&#xff0c;创邻科技入选与英特尔合作&#xff0c;在基于第四代英特尔至强处理器的支持下&#xff0c;利用软件防护扩展&#xff08;Software Guard Extension,SGX&#xff09; 技术&#xff0c;打造出了具备可信执行环境的图数据库产品&#xff0c;保护企业释放关联…