由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - one question about algorithm
相关主题
Excel Marco一个fortran问题:
How to encode YYYY-MM-DD?some problems with "cin"
有人能解释一下这段C++代码吗how to let cin get enter
what is used to represent a "tab" character in "sed"How to print \t in perl one-liner?
TIJ上写错了?请教char *和char []的判断
shortest path algorithm(dijkstra)的变形bourne shell 问题
how to check whether there are any control characters edited in a file?入门问题,perl里s@\_@@g 是什么意思?
问一道C++面试题求Optical Character Recognition入门教程
相关话题的讨论汇总
话题: shortest话题: key话题: character话题: characters话题: find
进入Programming版参与讨论
1 (共1页)
c***g
发帖数: 472
1
given one article, and a set of keywords
find the shortest length part which contain all the keywords
how to do that?
After translated, it will be: given a sequence, how to
find a shortest substring that contains all the items required. Example: a s
equence "abaccdefgacel" and a set of key words "a" "c", "d" and "e". The sho
rtest substring contianing all of the key words is "accde". Find one of such
shortest substrings.
j********e
发帖数: 7
2
Let me try:
step 1: traverse the string once, and count the occurance of each key
characters in the search string: i.e. a:3, c:3, d:1, e:1
step 2 : Recursion
/*"count" maps key characters to the # of occurance*/
/*"stringPath" is the longest string path so far containing all key characters
*/
void checkShortest(deque& stringPath, Map& count)
{
char head = stringPath.front();
char tail = stringPath.back();
/*Head character is not a key character*/
/*Or it is a key character, and h
s****u
发帖数: 118
3
are你sure就是一个字母的key?
而且看不懂你的什么意思 -_-

characters

【在 j********e 的大作中提到】
: Let me try:
: step 1: traverse the string once, and count the occurance of each key
: characters in the search string: i.e. a:3, c:3, d:1, e:1
: step 2 : Recursion
: /*"count" maps key characters to the # of occurance*/
: /*"stringPath" is the longest string path so far containing all key characters
: */
: void checkShortest(deque& stringPath, Map& count)
: {
: char head = stringPath.front();

j********e
发帖数: 7
4
I just worked off the simplified example in the original post. For string
keyword, the same token applies.

【在 s****u 的大作中提到】
: are你sure就是一个字母的key?
: 而且看不懂你的什么意思 -_-
:
: characters

s**********0
发帖数: 5
5
Definition: for single keyword X(consists of one or more characters),
*f_start1(X)
means the earliest poistion of the first character of X in the article.
*f_end1(X)
means the latest position of the first character of X in the article.
*f_start2(X)
means the earliest poistion of the last character of X in the article.
*f_end2(X)
means the latest position of the last character of X in the article.
For n keywords X1,X2,X3...,Xn, suppose the starting and ending position
of the shortest sub-article
i********r
发帖数: 131
6
One solution: O(N) time complexity
str is the input string,
K is the set of characters to be covered.
1. Create a structure to remember best result
Create a solution set R, which includes 0 solution.
A solution includes: a) starting index b) a bitmap showing which
characters are already covered.
2. scan through the string, for every character ch (with index = i)
2.1 if ch is not in K, do nothing and move on
2.2 if ch is in K, initialize a solution and put in R
s.index = i, ch
s****u
发帖数: 118
7
ft,character的key的话,简单的贪心就可以O(n)

【在 i********r 的大作中提到】
: One solution: O(N) time complexity
: str is the input string,
: K is the set of characters to be covered.
: 1. Create a structure to remember best result
: Create a solution set R, which includes 0 solution.
: A solution includes: a) starting index b) a bitmap showing which
: characters are already covered.
: 2. scan through the string, for every character ch (with index = i)
: 2.1 if ch is not in K, do nothing and move on
: 2.2 if ch is in K, initialize a solution and put in R

1 (共1页)
进入Programming版参与讨论
相关主题
求Optical Character Recognition入门教程TIJ上写错了?
网页input问题shortest path algorithm(dijkstra)的变形
关于 cin >> 操作how to check whether there are any control characters edited in a file?
请问有什么c++ algorithm and data structure 好的书吗?问一道C++面试题
Excel Marco一个fortran问题:
How to encode YYYY-MM-DD?some problems with "cin"
有人能解释一下这段C++代码吗how to let cin get enter
what is used to represent a "tab" character in "sed"How to print \t in perl one-liner?
相关话题的讨论汇总
话题: shortest话题: key话题: character话题: characters话题: find