题意:
给出个字符串,如果两个字符串中含有相同的字母说明两个字符串相同,问有多少个不同的字符串。
思路:
具有传递性,如果相同,相同,那么也一定相同
考虑用并查集维护。
但是所以枚举两个字符串显然不现实。
一共只有个字母,维护在某个字符串里每个字母的出现次数,如果两个字母在这个字符串里都出现过,合并所在集合,这样就能实现传递性了。
代码:
给出个字符串,如果两个字符串中含有相同的字母说明两个字符串相同,问有多少个不同的字符串。
具有传递性,如果相同,相同,那么也一定相同
考虑用并查集维护。
但是所以枚举两个字符串显然不现实。
一共只有个字母,维护在某个字符串里每个字母的出现次数,如果两个字母在这个字符串里都出现过,合并所在集合,这样就能实现传递性了。
Java8处理对象List集合之间的交集、并集、差集和去重
题目链接:http://codeforces.com/contest/776/proble
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M