10508 - Word Morphing
Moderator: Board moderators
10508 - Word Morphing
The description of this problem include:The number of words are unlimited! But I don't know how many words there are in one case at most. I've used array of 10000 to store the words but got runtime error! Please help me, thank you!
Re: 10508-Word Morphing ,runtime error!
One method, you can use malloc, because first line of each case will tell you how many words and how long of each word.sunhong wrote:The description of this problem include:The number of words are unlimited! But I don't know how many words there are in one case at most.
But, since the problem descript that "The number of words are unlimited!"
If there is any method needn't use so large memory?
or is there any method needn't care about the number of words ?
you can think about it, good luck

-
- Learning poster
- Posts: 54
- Joined: Sun May 18, 2003 1:19 am
- Location: Rio de Janeiro, Brazil
- Contact:
I've thinked a lot trying to find a way to do this problem without caring about the number of words, but I couldn't find any.
I coded with mallocs ... no problems with that, and I made a dfs to find the solution. It's ok , but I got TLE .
I optimized it with a matrix pre calculating the distances of each word, thus skipping unfeasible changes, but I still got TLE.
How did you guys got accepted ?
I coded with mallocs ... no problems with that, and I made a dfs to find the solution. It's ok , but I got TLE .
I optimized it with a matrix pre calculating the distances of each word, thus skipping unfeasible changes, but I still got TLE.
How did you guys got accepted ?
[]s
Mauricio Oliveira Carneiro
Mauricio Oliveira Carneiro
Each letter should be changed and can only be changed oncecarneiro wrote:I've thinked a lot trying to find a way to do this problem without caring about the number of words, but I couldn't find any.
I coded with mallocs ... no problems with that, and I made a dfs to find the solution. It's ok , but I got TLE .
I optimized it with a matrix pre calculating the distances of each word, thus skipping unfeasible changes, but I still got TLE.
How did you guys got accepted ?
you can try to think WHEN a letter be changed
you needn't use dfs. and needn't calcaulte all the distances between each word.
you can just to compare with the original one.

Why this code got wrong answer?
I just scan the intermediate word for how many different characters it has,
compared with the original one,and output them.But I got Wrong Answer,
why?Can anyone tell me the reason,or give me some input data?
Thank you indeed.
[c]#include "stdio.h"
#include "string.h"
char word[1000][1000];
int main()
{
int m,n,dif,i,j;
char temp[1000];
while(scanf("%d%d",&m,&n)==2)
{
scanf("%s",word[0]);
for(i=1;i<m;i++)
{
scanf("%s",temp);
dif=0;
for(j=0;j<n;j++)if((word[0][j]!=temp[j])&&(word[0][j]!=temp[j]+32)&&(word[0][j]!=temp[j]-32))dif++;
strcpy(word[dif],temp);
}
for(i=0;i<m;i++)printf("%s\n",word);
}
return 0;
}[/c]
compared with the original one,and output them.But I got Wrong Answer,
why?Can anyone tell me the reason,or give me some input data?
Thank you indeed.
[c]#include "stdio.h"
#include "string.h"
char word[1000][1000];
int main()
{
int m,n,dif,i,j;
char temp[1000];
while(scanf("%d%d",&m,&n)==2)
{
scanf("%s",word[0]);
for(i=1;i<m;i++)
{
scanf("%s",temp);
dif=0;
for(j=0;j<n;j++)if((word[0][j]!=temp[j])&&(word[0][j]!=temp[j]+32)&&(word[0][j]!=temp[j]-32))dif++;
strcpy(word[dif],temp);
}
for(i=0;i<m;i++)printf("%s\n",word);
}
return 0;
}[/c]
Retired from SJTU Accelerator 2004
-
- Learning poster
- Posts: 94
- Joined: Wed Jul 31, 2002 12:44 pm
- Location: Dacca, Bangladesh
- Contact:
i think you misunderstood the problem.
are you thinking that always number of words = number of letters+1 ? your program is only okay at that particular case... but the problem didn't say that... so the input might look like...
Greetings...
are you thinking that always number of words = number of letters+1 ? your program is only okay at that particular case... but the problem didn't say that... so the input might look like...
Code: Select all
10 3
abc
def
abf
abg
cdb
dbc
dbf
aec
aef
ada
Istiaque Ahmed [the LA-Z-BOy]
Hello, the LA-Z-BOy.
I was just thinking of the problem like you wrote.
number of words = number of letters+1
for the problem has this sentence:
According to your saying, what does this sentence mean?
And,what's output for your input?
I don't know how I can get string "ada".
I was just thinking of the problem like you wrote.
number of words = number of letters+1
for the problem has this sentence:
So I think number of words = number of letters+1;2.- A letter can be changed just once
According to your saying, what does this sentence mean?
And,what's output for your input?
I don't know how I can get string "ada".
Retired from SJTU Accelerator 2004
-
- Learning poster
- Posts: 54
- Joined: Sun May 18, 2003 1:19 am
- Location: Rio de Janeiro, Brazil
- Contact:
Alright, I'm just bitting my tong here...
I've recoded everything without carying about the number of words, doing as hujialie said, and finally got accepted with a 9 lines C code.
I believe this problem is not quite well written ... for this line should be : ALL THE WORDS IN THE INPUT SHALL BE USED.
Or just take out the "w" parameter of the input since it'll always be n+1.
Hope this helps everyone.
I've recoded everything without carying about the number of words, doing as hujialie said, and finally got accepted with a 9 lines C code.
I believe this problem is not quite well written ... for this line should be : ALL THE WORDS IN THE INPUT SHALL BE USED.
Or just take out the "w" parameter of the input since it'll always be n+1.
Hope this helps everyone.
[]s
Mauricio Oliveira Carneiro
Mauricio Oliveira Carneiro
-
- Learning poster
- Posts: 94
- Joined: Wed Jul 31, 2002 12:44 pm
- Location: Dacca, Bangladesh
- Contact:
damn... i thought the problem was harderer.... but in fact it is not... i now understand why this prob took 8sec+ for me to get AC
dear hujialie, sorry for misguiding you anyway
, really really sorry.
thanks hujialie, carneiro, Even; thanks everybody...goodluck...
ps. now i've changed my code, and got at in 0.061 sec.

you are right... the problem description never wrote that number of words = number of letters+1 but in fact it is true for the problemcarneiro wrote:I believe this problem is not quite well written ... for this line should be : ALL THE WORDS IN THE INPUT SHALL BE USED.

dear hujialie, sorry for misguiding you anyway

thanks hujialie, carneiro, Even; thanks everybody...goodluck...
ps. now i've changed my code, and got at in 0.061 sec.
Istiaque Ahmed [the LA-Z-BOy]