10100 - Longest Match

All about problems in Volume CI. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Postby Maxim » Tue Apr 29, 2003 10:20 pm

Please, anybody who got AC, help! It's killing me I can't get AC only because of silly input.

Maxim
User avatar
Maxim
New poster
 
Posts: 38
Joined: Tue Aug 27, 2002 12:36 am
Location: Croatia

Postby titid_gede » Wed Apr 30, 2003 4:44 pm

i think the problem is on the gets function. since i think it retains the '\n' caracter, so if blank line then strlen = 1 since there is one caracter that is '\n'.
Kalo mau kaya, buat apa sekolah?
titid_gede
Experienced poster
 
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Postby Adrian Kuegel » Wed Apr 30, 2003 6:25 pm

It is not a problem with gets. gets doesn't attach the '\n' in contrast to fgets.
But you should print blank also in cases where at least one of the lines contains only whitespace characters. Note that all characters but letters are considered as whitespace characters in this problem.
Adrian Kuegel
Guru
 
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Postby Maxim » Wed Apr 30, 2003 10:57 pm

Thank you, Adrian. I've tried with that blank stuff, but still getting WA.
Eventually, I've changed the way I read input. First, I read lines with gets() till end of file. Then I do calculation.

I know, it's DP problem. Is this procedure for searching white-space characters (as defined in text of problem) good one?

[c]cut out :wink: [/c]

Maxim
Last edited by Maxim on Fri May 02, 2003 2:23 am, edited 1 time in total.
User avatar
Maxim
New poster
 
Posts: 38
Joined: Tue Aug 27, 2002 12:36 am
Location: Croatia

Postby Adrian Kuegel » Wed Apr 30, 2003 11:14 pm

yes, I think so.
Do you consider something like
.test;,.test
as two words?
You can send me your whole program with private message if you want.
Adrian Kuegel
Guru
 
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Postby Maxim » Fri May 02, 2003 2:28 am

Thanks again, Adrian. Finally got AC. The problem was in bad task description. White-space characters are all characters except for letters and digits.

Maxim
User avatar
Maxim
New poster
 
Posts: 38
Joined: Tue Aug 27, 2002 12:36 am
Location: Croatia

10100 Why WA??..

Postby neowarez » Tue Jun 10, 2003 4:14 pm

Hi..

I dont understand why my code give me WA...


Can somenone who got AC tell me the output for this please..

Code: Select all

test test
test test
sdfasdf
(blank Line = (Length=0))
kgds
(Space charaters)
.....
asd 
The
the


My code output:

Code: Select all
 1. Length of longest match: 1
 2. Blank!
 3. Length of longest match: 0
 4. Length of longest match: 0
 5. Length of longest match: 1


Thanks!
Neo
User avatar
neowarez
New poster
 
Posts: 14
Joined: Tue May 06, 2003 11:04 pm
Location: Portugal

Help with correct output

Postby frehe » Tue Jun 17, 2003 5:46 pm

Since the problem is very much under specified I wonder what the correct output is for:
...
xyz
The
the
a b c
d b c
b 3
b 3
b..a
b.a

I guessed:
1. Blank!
2. 1
3. 2
4. 2
5. 2

But I still don't solve the problem.
frehe
New poster
 
Posts: 1
Joined: Tue Jun 17, 2003 5:42 pm

Postby Larry » Thu Aug 28, 2003 5:28 am

What assumptions can I make about this problem? I've read the boards, used the same code for many other LCS problems, and still WA.. are these case sensitives? Anyone have any more critical cases?
Larry
Guru
 
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City

Postby Larry » Thu Aug 28, 2003 5:30 am

I tried everything and still WA.. grr.! :cry:
Larry
Guru
 
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City

Postby Julien Cornebise » Sat Aug 30, 2003 1:22 am

Hello
I'm having WA for this problem, and after having rewrote it from scratch twice, and read the whole forum. So I'm now going to an extremity I never used before : posting my algorithm and my whole source here, hoping that someone we'll help me ;)
The algo is simple : DP with a table l[i][j] where l[i][j] is the length of the longest matching sequence (run) of words ending exactly on word i of line 1 and word j of line 2 (included).
So if the word I of line1 and word J of line2 does not match, l[i][j] = 0, else
l[i][j]= 1+l[i-1][j-1].
Here's the corresponding source... It's driving me mad ! Any help will be really appreciated.
[cpp]
:: REMOVED 2 DAYS LATER::
[/cpp]
Thanks ![/c]
Last edited by Julien Cornebise on Sat Aug 30, 2003 3:26 pm, edited 1 time in total.
Julien Cornebise
Experienced poster
 
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France

Postby Maxim » Sat Aug 30, 2003 1:05 pm

Julien Cornebise wrote:Hello
I'm having WA for this problem, and after having rewrote it from scratch twice, and read the whole forum. So I'm now going to an extremity I never used before : posting my algorithm and my whole source here, hoping that someone we'll help me ;)
The algo is simple : DP with a table l[i][j] where l[i][j] is the length of the longest matching sequence (run) of words ending exactly on word i of line 1 and word j of line 2 (included).
So if the word I of line1 and word J of line2 does not match, l[i][j] = 0, else
l[i][j]= 1+l[i-1][j-1].
Here's the corresponding source... It's driving me mad ! Any help will be really appreciated.


If i-th word of line 1 and j-th word of line 2 don't match, then l[i][j] shouldn't be 0. l[i][j] tells you the length of longest common subsequence (LCS) of first i words from line 1 and first j words from line 2. So, if they don't match, l[i][j] = max { l[i][j - 1], l[i - 1][j] }. In other words, set l[i][j] to larger from these two: LCS of first i words from line 1 and first j-1 words from line 2, or LCS of first i-1 words from line 1 and first j words from line 2.
Hope you understand it...

Maxim
User avatar
Maxim
New poster
 
Posts: 38
Joined: Tue Aug 27, 2002 12:36 am
Location: Croatia

Postby Julien Cornebise » Sat Aug 30, 2003 3:25 pm

THANK YOU VERY MUCH Maxim !! :D
I finally got AC, thanks to your advice.
I perfectly understand what you mean, given that I already used that LCS algo some time ago for another problem.
The trouble was that I thought here that longest MATCH meant longest RUN, not longest SUBSEQUENCE : for me we were asked the length of the longest common RUN, not the longest common SUBSEQUENCE !!!!! The difference is in input like
a b c d e
a c e
Longest common run : 1
Longest common subsequence : 3
Somebody said that problem was too much under stated (different interpretations of blank line, non letter meaning non alpha NUMERIC, etc)... I guess it's true. But it might also be my english vocabulary that's too less developed :/
Well, THANKS once again for having clarified my mind, I remove my code from the forum...
Julien Cornebise
Experienced poster
 
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France

Postby little joey » Sat Aug 30, 2003 3:28 pm

Thanks!
I made exactly the same mistake four months ago when I tried to solve this problem for the first time. Now I finally got AC!

But the problem lies in the problem description and the lack of definition of "longest match". I read it as "longest match of consecutive words" in stead of "longest match of words in the same order".
They want to guess the intensions of other groups by checking the changed sections of messages. First they have to get the length of longest match.

I interpreted as finding the longest unchanged section, which would be in line with the story and would lead to my first definition of "longest match". Julien (and probably more people who got WA) must have read it the same way as I did.

To summarize:
The correct answer for
Code: Select all
This is a test.
This is not a test.
is 4, not 2.
User avatar
little joey
Guru
 
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Postby little joey » Sat Aug 30, 2003 3:29 pm

Hi hi.
We were writing our postings at the same time! Julien and I said exactly the same thing.
User avatar
little joey
Guru
 
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

PreviousNext

Return to Volume CI

Who is online

Users browsing this forum: No registered users and 1 guest