7-4 哈利·波特的考试

 题目重述:

       输出一个点,该点到其他所有点的距离的最大值最小,并输出最小的最大值。如果有任意两点无法到达,则输出0。(边权非负)

思路:

       用FLoyd求出任意两点间距离的最小值。循环所有点,存储该节点到其他点的最大值maxl。最小的maxl值即为所求。若任意两点间距离无穷大,则不符合要求。

#include<iostream>
#include<cstring>
using namespace std;

const int N = 220, inf = 0x3f3f3f3f;
int g[N][N];
int n, m;

int main() {


    cin >> n >> m;
	memset(g, 0x3f, sizeof g);
	cout << sizeof g << endl;
	for(int i = 1; i <= n; ++ i) {
		g[i][i] = 0;
	}
	

	while(m --) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a][b] = g[b][a] = min(g[a][b], c);
	}

	//先用Floyd求任意两点的最短路
	for(int k = 1; k <= n; ++ k) {
		for(int i = 1; i <= n; ++ i) {
			for(int j = 1; j <= n; ++ j) {
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
				//cout << g[i][j] << endl;
			}
		}
	}

	//找出可以与其他点均相通的点和最短的最长魔咒
	int ans = inf, pos = -1;
	bool flag = true;
	for(int i = 1; i <= n; ++ i) {
		int maxl = 0;
		for(int j = 1; j <= n; ++ j) {
			//
			if(g[i][j] == inf) {
				flag = false;
				break;
			}
			maxl = max(maxl, g[i][j]);
		}
		//if(!flag) continue;
		if(ans > maxl) {
			ans = maxl;
			pos = i;
			//printf("%d %d\n", ans, pos);
		}
	}
	if(!flag) cout << "0" << endl;
	else cout << pos << ' ' << ans << endl;
	return 0;
}

根据提供的引用内容,我们可以了解到《哈利波特》是一部关于哈利、赫敏、罗恩等人在大法师邓布利多的帮助下,使用魔法抵抗伏地魔的故事。同时,根据引用和引用,我们可以使用Python对小说中的人物名字和出现频率进行统计和分析。 以下是Python代码示例: 1. 统计人物名字TOP20的词语 ```python import jieba import pandas as pd from collections import Counter from pyecharts import Bar # 读取小说文本 with open('harry_potter.txt', 'r', encoding='utf-8') as f: text = f.read() # 使用jieba分词 words = jieba.lcut(text) # 统计人物名字出现的次数 names = ['哈利', '赫敏', '罗恩', '邓布利多', '马尔福', '斯内普', '小天狼星'] names_count = Counter([word for word in words if word in names]) # 绘制柱状图 bar = Bar('主要人物Top20', background_color='white', title_pos='center', title_text_size=20) x = names_count.most_common(20) bar.add('', [i[0] for i in x], [i[1] for i in x], xaxis_interval=0, xaxis_rotate=30, is_label_show=True) bar.render() ``` 2. 统计整部小说出现最多的词语TOP15 ```python import jieba import pandas as pd from collections import Counter # 读取小说文本 with open('harry_potter.txt', 'r', encoding='utf-8') as f: text = f.read() # 使用jieba分词 words = jieba.lcut(text) # 统计词语出现的次数 words_count = Counter(words) # 去除停用词 stopwords = pd.read_csv('stopwords.txt', index_col=False, quoting=3, sep='\t', names=['stopword'], encoding='utf-8') words = [word for word in words if word not in stopwords] # 统计出现最多的词语TOP15 top15 = words_count.most_common(15) print(top15) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值