当前位置:网站首页>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 :

边栏推荐
- createjs easeljs
- Markdown directory generation
- 了解小程序的笔记 2022/7/3
- Redux - learning notes
- Unity editor expansion - scrolling list
- Dom4j traverses and updates XML
- Osganimation library parsing
- Simple demo of solving BP neural network by gradient descent method
- How to deal with the core task delay caused by insufficient data warehouse resources
- Baidu editor ueeditor changes style
猜你喜欢

Binary to decimal, decimal to binary

Explain sizeof, strlen, pointer, array and other combination questions in detail

Mortgage Calculator

Graphics_ Games101/202 learning notes

单调栈-84. 柱状图中最大的矩形

二进制转十进制,十进制转二进制

UE4 source code reading_ Bone model and animation system_ Animation node

Notes on understanding applets 2022/7/3

Unity interactive water ripple post-treatment

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)
Gradle's method of dynamically modifying APK package name
Markdown learning
Simple demo of solving BP neural network by gradient descent method
Vscode, idea, VIM development tool shortcut keys
20220630学习打卡
22-05-26 西安 面试题(01)准备
Unity interactive water ripple post-treatment
Baidu editor ueeditor changes style
Message queue for interprocess communication
[concurrent programming] thread foundation and sharing between threads
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
JS non Boolean operation - learning notes
[rust notes] 11 practical features
Monotonic stack -503 Next bigger Element II
Installation of PHP FPM software +openresty cache construction
[concurrent programming] consistency hash
Dom4j traverses and updates XML
Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
Monotonic stack -84 The largest rectangle in the histogram