最小表示法及其证明
问题
对于一个字符串S,求S的循环的同构字符串S’中字典序最小的一个。
我们举例说明,字符串”abcd”的循环同构字符串有:["abcd", "bcda", "cdab", "dabc"]
。
题目的目标是 …
more ...对于一个字符串S,求S的循环的同构字符串S’中字典序最小的一个。
我们举例说明,字符串”abcd”的循环同构字符串有:["abcd", "bcda", "cdab", "dabc"]
。
题目的目标是 …
more ...There are a lot of interview problem based on the 1D-array, which is the one of the easiest “data structure”.
But the problem about that simple data structure might not be that simple. Here is the summary of the problem about 1D-array.
Of course, most of them come from …
more ...Simple and easy, solved by two lines of python code.
ls = filter(lambda y: y, map(lambda x: x.strip(), raw_input()[1:-1].split(",")))
print len(set(ls))
Brute force. Just enumerate the beginning and the end of the substring, and …
more ...This problem is from the book “Algorithm 4th edition” (Exersise 4.1.10)
There are N cities and M undirected roads between those cities. People can travel to any city along the roads.
One day, a war breaks out. Our cities are under attack! As we can’t defend …
more ...Trun x => X
or X => x
to make the number of ‘x’ is equal to the number of ‘X’.
n = int(raw_input())
hamsters = [c for c in raw_input()]
sits = hamsters.count('x')
stands = hamsters.count('X')
if sits == stands:
print 0
print ''.join(hamsters)
else:
if sits > stands …
It has been months that I didn’t participate in the contest on CF, now I’m back. :)
This round of contest makes me confused that the problem B and C is a little bit too twisted, if you can’t catch the vital point, you will get a …
more ...交错路:设P是图G的一条路,如果P的任意两条相邻的边一定是一条属于M而另一条不属于M,就称P是一条交错路。
通俗点来说,就是把一个图中的路径染成红黑两种。然后找出一条路,使这条路红黑 …
more ...