随笔分类 -  解题报告 Solutions

摘要:问题:How can anagrams result from sequences of stack operations? There are two sequences of stack operators which can convert TROT to TORT:[i i i i o o o oi o i i o o i o]whereistands for Push andostands for Pop. Your program should, given pairs of words produce sequences of stack operations which con 阅读全文
posted @ 2011-06-25 12:03 skyline0623 阅读(230) 评论(0) 推荐(0)
摘要:Problem:Fire NetSuppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East 阅读全文
posted @ 2011-06-15 11:33 skyline0623 阅读(285) 评论(0) 推荐(0)
摘要:问题:输入N个0~9的整数,可以重复,从小到大打印出这N个数字组成的所有N位数。e.g输入:4002输出:002400420204024004020420200420402400400240204200策略:这道题是一个同学问我的,她帮一个同学完成作业。我刚看到问题的时候,第一个想法就是求出全排列,时间复杂度是O(n!)。写个算法除去重复的数列,再写一个算法排序,一个排序算法比如快速排序的平均时间复杂度O(n*lg n)。但也立马否定了。这个算法在整数个数增加后空间复杂度、时间复杂度都会有巨大的增长。这个算法好理解,但也不够巧妙。其实可以考虑可以在寻找全排列的时候就可以以升序的顺序输出。因为升 阅读全文
posted @ 2011-04-16 08:34 skyline0623 阅读(1189) 评论(0) 推荐(0)