Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point…
有N个改名的动作,输出改完名的最终结果. 拿map做映射 #include <iostream> #include <map> #include <string> using namespace std; map<string,string> mp; map<string,int> vis; int n; string s1,s2; int main() { cin>>n; map<string,string>::iter…
Misha and Changing Handles CodeForces原题是英文,这里就直接上中文好了,翻译不是太给力,但是不影响做题 ^▽^ Description  神秘的三角洲里还有一个传说中的谜题等你来解开!三角洲里的小学生小明是个小天才,知天文晓地理还能夜观星象算命,好多疯狂的小朋友都想去请他给自己换个好听的名字.但是天才小明,他总是在思考31维宇宙空间的奥秘,神游天外,所以在给小朋友们敲他们想要的名字的时候,偶尔会取出一些不那么完美的名字.有的小朋友们换了名字以后不太满意,于是它…
题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上去,那么就保证更新了初始的名字,这也是唯一要思考的地方了:) */ #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cmath&…
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point…
B. Misha and Changing Handles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now cha…
题意:给出n个名字变化,问一个名字最后变成了什么名字 先用map顺着做的,后来不对, 发现别人是将变化后的那个名字当成键值来做的,最后输出的时候先输出second,再输出first 写一下样例就好理解了 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<m…
Description Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used a…
题目链接:http://codeforces.com/problemset/problem/501/C 题目意思:有 n 个点,编号为 0 - n-1.给出 n 个点的度数(即有多少个点跟它有边相连)以及跟它相连的点的编号的异或结果.最后需要输出整幅图的所有边的情况. 这道题确实是一道很好的题目!!!!它说拓扑排序的变形,需要队列的运用,还有就是异或计算的性质!!!(非一般厉害) 由于是无向无环的简单图,换言之就是一棵树啦^_^.那么它就肯定有叶子结点,叶子节点的度数为1,此时它相邻点的异或结果…
832D - Misha, Grisha and Underground 思路:lca,求两个最短路的公共长度.公共长度公式为(d(a,b)+d(b,c)-d(a,c))/2. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define ls rt<<1,l,m #define rs rt<<1|1,m+1,r const int INF=0x3f3f3f3f; ; ; ve…