觉得浮夸了四年,漠然发现原来是浮躁了四年!

摘要: 今天对KMP的认识又加深一点了,可是又不是很能用语言来表达!题目大意:给定两个字符串,比如abcd,dcab,需要把它连接起来,但是需要遵循两个条件,1 最短原则 2 长度相同的前提下字典序的优先连接原则:如果第一个字符串的后缀(长度为n)和第二个字符串的前缀(长度为n)相同,那么连接的时候可以省去相同的n个字符,本来有2n个字符;仍然以上面的两个字符串为例,有两种连法,abcdcab和dcabcd,显然第二个字符串更短,所以输出dcabcd;解决办法:两次KMP运用一次KMP可以计算出两个字符串的前缀和后缀的相同长度n;两次KMP后比较n的值即可; 1 #include<iostrea 阅读全文
posted @ 2013-04-29 23:10 heat nan 阅读(150) 评论(0) 推荐(0)
摘要: Problem DescriptionIn the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and your present's card number will b 阅读全文
posted @ 2013-04-29 11:46 heat nan 阅读(206) 评论(0) 推荐(0)