博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数集合有多少个TOJ(2469)
阅读量:6997 次
发布时间:2019-06-27

本文共 748 字,大约阅读时间需要 2 分钟。

题目链接:

感觉这个题目有点问题,算了不管他了,反正A了。

这里要注意的是求这个集合有多少种,那么就是要剔除重复数后,再数一下有多少个。

难一点的算法我也不会,是帆哥教我的,就是用map<int,bool>,只要maps.find(p)要是没有,就是一个不重复的集合ans++,或者maps.size();

这个题目的问题在于,father[i]里面存的是根节点,但是,我直接maps.find(father[i])却WA了,我改成p=Find_Set(i),find(p)就AC了,很不懂。

#include 
#include
#include
using namespace std;int father[105];int Find_Set(int x){ if(x!=father[x]) father[x] = Find_Set(father[x]); return father[x];}int main(){ int t; scanf("%d",&t); while(t--) { map
maps; int n,m; scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) father[i] = i; int x,y; for(int i=0; i

 

转载于:https://www.cnblogs.com/TreeDream/p/5713901.html

你可能感兴趣的文章