题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018
思路:并差集找连通块,然后找连通块里的欧拉图和半欧拉图(ps:欧拉图:节点度数全部为偶数;半欧拉图:有且只有两个度数为奇数的节点,这两种图都可以一笔画出。)而如果奇数点更多,对于一个连通图而言,有这样的一个性质:其需要画的笔数=度数为奇数的点数除以2
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <bitset>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream

该博客介绍了如何运用并查集数据结构解决HDU 3018题目的算法问题。通过并查集找到图的连通块,并判断每个连通块内的图是欧拉图还是半欧拉图。欧拉图定义为所有节点的度数为偶数,半欧拉图则有且仅有两个度数为奇数的节点。当奇数度数的节点超过两个时,根据图的性质,一笔画的笔数等于奇数节点数除以2。
最低0.47元/天 解锁文章
11万+

被折叠的 条评论
为什么被折叠?



