码迷,mamicode.com
首页 > 其他好文 > 详细

P2814 家谱

时间:2019-07-04 13:02:25      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:并查集   str   char   string   bitset   names   一点   www   为什么   

我真没什么创意了woc。。

so,为什么一道水题是蓝色的???哦哦哦,水好像就是蓝色的,emmm那就不是恶意评分了嘤嘤嘤

。。。

好吧实际上可能是非c党对于字符串的处理需要进行编号和结构体,会麻烦一点吧。。。

ok说题目,这题实际上也没啥好说的,map+并查集,最基本的并查集,然后,就过了。顺带一提我的map是现学的,所以可能从某种意义上提升了这道题对我的难度吧。。。

 1 #include<set>
 2 #include<map>
 3 #include<list>
 4 #include<queue>
 5 #include<stack>
 6 #include<string>
 7 #include<cmath>
 8 #include<ctime>
 9 #include<vector>
10 #include<bitset>
11 #include<memory>
12 #include<utility>
13 #include<cstdio>
14 #include<sstream>
15 #include<iostream>
16 #include<cstdlib>
17 #include<cstring>
18 #include<algorithm>
19 using namespace std;
20 
21 string z,y;
22 map<string,string>p;//map
23 
24 string find(string x){//查找该集合的代表元
25     return x==p[x]?x:p[x]=find(p[x]);
26 }
27 
28 int main(){
29     char zy;
30     cin>>zy;//读入第一个字符
31     while(zy!=$){
32         cin>>z;
33         if(zy==#){
34             y=z;
35             if(p[z]=="") p[z]=z;
36         }
37         else if(zy==+){
38             p[z]=y;
39         }
40         else{//输出
41             cout<<z<< <<find(z)<<endl;
42         }
43         cin>>zy;
44     }
45     return 0;
46 }

做完这题有种到处认爹的感觉???

算了看它是蓝色水题的面子上就不纠结了嘤嘤嘤

P2814 家谱

标签:并查集   str   char   string   bitset   names   一点   www   为什么   

原文地址:https://www.cnblogs.com/hahaha2124652975/p/11131726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!