烧饼的技术乱讲
In: Algorithm
23 三 2010一直以来我对数的排列这类算法问题都感到很头痛,曾经囫囵吞枣看过一些算法,可是浅尝辄止,没有实际操作所以每次都忘记。上周三算法分析与设计课的内容是递归,老师正好提到了排列数这一问题,于是就有机会稍微进行一些研究。 一个排列(permutation)就是对一组对象或者数值按照某种特定的方式进行排列组织(ar-rangement),为了方便起见我们以一个数集{1, 2, 3}为例,它的全排列共有3!=6种,即{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1},上述列举排列的顺序又称为按字典序列举排列,具体将在下文进行叙述。 一、字典序 在Wikipedia中,字典序的解释是这样的: In mathematics, the lexicographic or lexicographical order, (also known as dictionary order, alphabetic order or lexicographic(al) product), is a natural order structure of the Cartesian product of two ordered sets. 如果你拥有一个字典,那么里面所有的字符串都是按照字典序来进行排序的,假设有两个字符串: a1, [...]
其实一直都挺想做Topcoder的算法比赛的,不为别的,锻炼一下自己的思维以及写一些小代码的速度和准度。其实很糟糕的是我在Topcoder的比赛中一直会在第一题花去很长的时间,实际上可能整个思路在5、6分钟就能出来了,只是这个代码上的错误,那个代码上的错误,然后为了某个小粗心又要单步调试很长的时间……后来在学校因为时间的关系一直没什么机会做,这次发现正好时间在北京时间晚上7点,于是就注册了。
这次有三题,本文先将题目列出,因为题目可能就要花去很大的篇幅。比赛中我只做出了第一题-__-||接下来要把后面两题给思考一下再放出答案(也顺便感受一下Live Writter的代码高亮工具:D)
Point 250: FourBlocksEasy
Point 500: NumericPerfection
Point 1000: RotatingTriangles
I'm now a graduate student of Computer Applied Technology in Tongji University. I like Computer Graphics, Web 2.0, Magic, Music and am partially a geek. This blog is about C++, algorithm, cg, comments and other things I may get in touch with in the near future. Hope everyone enjoy this little site. Contact me: 4everlove.xu AT gmail.com