Stack!
以前一直以为栈是个很复杂的东西,今天第一次用这个东西写题居然一次AC,欣喜之余发篇文纪念一下 #(滑稽)
以前一直以为栈是个很复杂的东西,今天第一次用这个东西写题居然一次AC,欣喜之余发篇文纪念一下 #(滑稽)
碰到一个题目
题目描述
玛雅人有一种密码,如果字符串中出现连续的2012四个数字就能解开密码。给一个长度为N的字符串,(2=<N<=13)该字符串中只含有0,1,2三种数字,问这个字符串要移位几次才能解开密码,每次只能移动相邻的两个数字。例如02120经过一次移位,可以得到20120,01220,02210,02102,其中20120符合要求,因此输出为1.如果无论移位多少次都解不开密码,输出-1。
输入
第一行输入N,第二行输入N个数字,只包含0,1,2
输出
样例输入
5
02120样例输出
1
虽然知道是bfs,但实现起来总觉得哪里不对,参考大佬们的博客后解决了几个难点:
关于碰到的一次二叉树的优化……
转载自ICS161,学英语,自娱自乐
To traverse(遍历) means to visit the vertices in some systematic order. You should be familiar with various traversal methods for trees:
preorder: visit each node before its children.
postorder: visit each node after its children.
inorder (for binary trees only): visit left subtree, node, right subtree.
We also saw another kind of traversal, topological ordering(拓扑排序), when I talked about shortest paths.
Today, we'll see two other traversals: breadth first search (BFS) and depth first search (DFS). Both of these construct spanning trees with certain properties useful in other graph algorithms. We'll start by describing them in undirected graphs, but they are both also very useful for directed graphs.
这两天看了廖雪峰老师的 Git 教程,受益匪浅。
以下为常用基本命令总结:
git init
git add <file>
,git commit -m "messages"
git status
git diff
git log
git reset --hard commit_id
git relog
git check -- file
git reset HEAD file
git rm
git remote add origin git@server:path/repo.git
git push -u origin master
git push origin master
git clone ssh://user@domain.com/repo.git
git branch
git branch <name>
git checkout <name>
git checkout -b <name>
git merge <name>
git branch -d <name>
git tag <name>
默认为HEADgit tag -a <tagname> -m "balabala……"
git tag
git push origin --tags
git tag -d <tagname>
git push origin :refs/tags/<tagname>