jfo planet

Hope is the best gift that tomorrow gives.

  • 首页
  • 分类
  • 归档
  • 标签
  • 搜索
close

KMP算法(子串包含问题)

发表于 2009-09-09   |   分类于 c/c++/algorithm
问题:给你两个字符串A和B,问B是否为A的子串(A是否包含B)。比如,字符串A="abcdgo",字符串B="dgo",我们就说B是A的子串。假如,A="abababaababacb",B="ababacb",我们来看看KMP是怎么工作的。我们用两个下标i和j分别表示A和B的当前比较位置,其中A[i-j+1..i]与B[0..j-1]完全匹配。也就是说,i不断增加,随着i的增加j相应地变化,且j满足以A[i-1]结尾的长度为j的字符串正好匹配B串的前 j个字符(j当然越大越好),现在需要检验A[i]和B[j]的关系。当A[i]=B[j]时,i和j各加一;什么时候j=m(B的长度)了,我们就说B是A的子串,并且可以根据这时的i值算出匹配的位置。当A[i+1]<>B[j+1],KMP的策略是调整j的位置 (减小j值为j’+1)使得A[i-j’..i]与B[0..j’];然后继续检查A[i]和新的B[j]是否相等。我们看一看当 i = j = 5时的情况:  i = 0 1 2 3 4 ...
阅读全文 »

【★】最长递增子序列

发表于 2009-09-08   |   分类于 c/c++/algorithm
POJ 2533 / ZOJ 2136Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11175 Accepted: 4720 DescriptionA numeric sequence of ai is ordered if a1 < a2 < … < aN. Let the subsequence of the given numeric sequence (a1, a2, …, aN) be any sequence (ai1, ai2, …, aiK), where 1 <= i1 < i2 < … < iK <= N. For example, sequence (1, 7, 3, 5, ...
阅读全文 »

【★】Team Them Up!

发表于 2009-09-04   |   分类于 c/c++/algorithm
POJ 1112Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2348 Accepted: 610 Special Judge DescriptionYour task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of the teams; every team has at least one member; every person in the team knows every other person in his team; teams are as close in th ...
阅读全文 »

【★】tiling

发表于 2009-09-01   |   分类于 c/c++/algorithm
POJ 2411Mondriaan’s Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 3322 Accepted: 1914 DescriptionSquares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his ‘toilet series’ (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a l ...
阅读全文 »

Google Book

发表于 2009-08-30   |   分类于 c/c++/algorithm
ZOJ Problem Set - 3197 You, the best hacker in the world, want to download the books published on Google Book. After some investigation, you found that the address of each page consists of two parts. The first part is the page number, the second part is the signature which is unique for each page. To get the signature, you can send the query to the server. The query has one parameter, which indicates the page number. The server will return the signature of the required page, and it ...
阅读全文 »

Maze

发表于 2009-08-30   |   分类于 c/c++/algorithm
ZOJ Problem Set - 3225 There is a maze that has n entrances in the top while n exits in the other side.In this maze, Mr Maze can go down, go left, go right but he can’t go up.What’s more, he have to turn left or right if he could. Both entrances and exits will be numbered from left to right starting by 1.Now, Mr Maze is at No.a extrance and he wants to go to No.b exit.And he has only one chance to go straight when he has to turn.Of course he can only do this when he could go forward.Can he get ...
阅读全文 »

【★】Sticks

发表于 2009-08-28   |   分类于 c/c++/algorithm
Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 57061 Accepted: 12462 DescriptionGeorge took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which comput ...
阅读全文 »

【★】Solving the Problems

发表于 2009-08-28   |   分类于 c/c++/algorithm
Programming is fun, Aaron is addicted to it. In order to improve his programming skill, he decides to solve one programming problem per day. As you know, different problems have different properties, some problems are so difficult that there are few people can solve it, while some problems are so easy that almost everyone is able to tackle it.Programming skill can be measured by an integer p. And all problems are described by two integers ai and bi. ai indicates that if and only if P >= ai ...
阅读全文 »

【★】Tree of Tree

发表于 2009-08-28   |   分类于 c/c++/algorithm
You’re given a tree with weights of each node, you need to find the maximum subtree of specified size of this tree. Tree Definition A tree is a connected graph which contains no cycles.InputThere are several test cases in the input.The first line of each case are two integers N(1 <= N <= 100), K(1 <= K <= N), where N is the number of nodes of this tree, and K is the subtree’s size, followed by a line with N nonnegative integers, where the k-th integer indicates the weight of k-th ...
阅读全文 »

重装Vista或Windows7后,Ubuntu无法启动的解决方案

发表于 2009-08-14   |   分类于 Windows
http://forum.ubuntu.org.cn/viewtopic.php?f=139&t=178189&sid=687746e8cfd169f1f5caeea42dd31ca1&start=15其实,vista、win7 尽管使用BCD,但也会读取boot.ini的内容(以兼容 xp 方式)。所以老办法仍然有效。你可以在 C: 下自行建立一个 boot.ini 文件,写上:[boot loader][operating systems]c:grldr.mbr="grub4dos"与 xp 不同的是,这对引号是必须的。并且必须用 grldr.mbr,然后把 grub4dos 压缩包里面的 grldr.mbr 以及 grldr 两个文件都放置在 c: 下即可。也 无需从 linux 分区拷贝任何文件, grub4dos 认识所有的 linux 分区(只要你的 grub4dos 足够新),会自动找到并使用里面的 menu.lst(只要你没有在其他分区里放置 menu.lst 来干扰他的运作)。因此你自行建立了 boot.ini 并拷贝了 ...
阅读全文 »
1…262728…61
jfo

jfo

605 日志
38 分类
4 标签
RSS
GitHub 微博
友情链接
  • 收藏夹
  • 网络剪贴板
  • 爱逛吧
© 2007 - 2018 jfo
由 Hexo 强力驱动
主题 - NexT.Pisces