当前位置:网站首页>Six dimensional space (C language)
Six dimensional space (C language)
2022-07-03 08:50:00 【Cap07】
Global variables.h( Declaration of global variables ):
// Store the declaration of global variables , Pay attention to add extern
extern int Graph[100][100]; // Adjacency matrix
extern int V, W; // Points and edges
extern int visited[100]; // Determine whether to access Global variables.cpp( Setting of global variables ):
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include"Global variables.h"
// Set global variables
int Graph[100][100]; // Adjacency matrix
int V, W; // Points and edges
int visited[100]; // Determine whether to access head.h( The header file ):
void BuildGraph();
void SDS();
int BFS(int v);head.cpp( Implementation of functions in header file ):
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include"head.h"
#include"Global variables.h"
void BuildGraph() { // Set up a map
int i, j, n1, n2;
for (i = 0; i < V; i++) { // initialization
for (j = 0; j < V; j++) {
Graph[i][j] = 0;
}
}
for (i = 0; i < W; i++) { // Set up a map
scanf("%d%d", &n1, &n2);
Graph[n1][n2] = 1;
Graph[n2][n1] = 1;
}
}
void SDS() {
int i, j;
float rate;
for (i = 0; i < V; i++) {
for (j = 0; j < V; j++)
visited[j] = 0;
rate = (float)BFS(i) / V;
printf("%d: %.2f%%\n", i + 1, rate * 100);
}
}
int BFS(int v) {
int cnt = 1, level = 0, last = v, i, n, tail;
int que[1000] = {}, rear, front; // Simulation queue
rear = front = 0;
visited[v] = 1;
que[rear] = v;
rear++;
while (rear > front) {
n = que[front];
front++;
for (i = 0; i < V; i++) {
if (visited[i] == 0 && Graph[n + 1][i + 1] == 1) {
visited[i] = 1;
que[rear] = i;
rear++;
cnt++;
tail = i;
}
}
if (n == last) {
level++;
last = tail;
}
if (level == 6) {
break;
}
}
return cnt;
}
ceshi1.cpp( The main function ):
#define _CRT_SECURE_NO_WARNINGS // Six degrees of space
#include<stdio.h>
#include<stdlib.h>
#include"head.h"
#include"Global variables.h"
int main() {
scanf("%d%d", &V, &W);
BuildGraph();
SDS();
return 0;
}test result :

边栏推荐
- 求组合数 AcWing 886. 求组合数 II
- DOM 渲染系统(render mount patch)响应式系统
- [concurrent programming] collaboration between threads
- Notes and bugs generated during the use of h:i:s and y-m-d
- PHP uses foreach to get a value in a two-dimensional associative array (with instances)
- PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
- 二进制转十进制,十进制转二进制
- MySQL three logs
- Unity multi open script
- [rust notes] 06 package and module
猜你喜欢

Alibaba canaladmin deployment and canal cluster Ha Construction

100 GIS practical application cases (78) - Multi compliance database design and data warehousing

Unity editor expansion - controls, layouts

First Servlet

Collection interface

Allocation exception Servlet
![[concurrent programming] concurrent tool class of thread](/img/16/2b4d2b3528b138304a1a3918773ecf.jpg)
[concurrent programming] concurrent tool class of thread

Es8 async and await learning notes

Simple demo of solving BP neural network by gradient descent method

Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
随机推荐
Sending and receiving of request parameters
Dealing with duplicate data in Excel with xlwings
Osgearth topographic shading map drawing
[concurrent programming] atomic operation CAS
22-05-26 西安 面试题(01)准备
Really explain the five data structures of redis
VIM learning notes from introduction to silk skating
[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
UE4 source code reading_ Mobile synchronization
Graphics_ Learnopongl learning notes
[rust notes] 12 closure
Collection interface
分配异常的servlet
php public private protected
单调栈-42. 接雨水
Dom4j遍历和更新XML
How to delete CSDN after sending a wrong blog? How to operate quickly
数据库原理期末复习
Unity editor expansion - the design idea of imgui
Try to reprint an article about CSDN reprint