You are doing a classical way which is fine (considering the size of the problem).
I'd like to do it a more abstract way that: * encode each cell to a number with ((row << 3) + col) so there will be 64 cells and thus 64 numbers to represent them * treat each number as a node and the nodes can be connected if ((row1 != row2 || col1 != col2) && 3 == (abs(row1 - row2) + abs(col1 - col2))) - the valid knight moves * now you have O(64^3) algorithm to calculate all the pairwise distances * for the problem you just look up the table and print the answer Regards 8-) On Fri, Dec 14, 2012 at 10:13 AM, thefourtheye <[email protected] > wrote: > Hi Neal & Parker, > > Thanks a lot guys, I ran a testcase with an empty line at the end and as > you guys pointed out, it failed... I changed it the way you guys suggested, > it worked and got AC :) > > Now, Can I improve my solution? I believe what I am doing in Update > function is overkill, plain BFS would suffice, right? > > And I am more inclined to use maps, is there any other way in which I > could have represented the data better? > > > On Thursday, December 13, 2012 4:08:18 PM UTC+5:30, Porker wrote: > >> Agree with Neal >> >> To read till the end of file, I would suggest to use >> >> while (cin >> str1 >> str2) { >> .. >> } >> >> and then there is no need to take care of the last 'endl'. >> >> the following code give me accepted. >> >> http://ideone.com/ORzXcK >> >> Parker >> >> On 2012/12/13 13:34, Neal Zane wrote: >> > Not sure but could be the last 'endl' for the last line you >> > intentionally avoided. Note that UVa reports WA on mis-formatting, >> > insteadof PE (long ago since host migration). >> > >> > The while loop judging cin.eof() could also fail it if the input file >> > has extra lines that althoughthe test cases are read but in the tail >> > there are some blanks, cin.eof() is true and you are still running and >> > the output could be corrupted.It's safer to use just: >> > while (cin >> str1 >> str2) { >> > .. >> > } >> > >> > The code logic looks fine to me(hard to tell though, UVa is lining up >> > judging queuefor now.) >> > >> > Regards >> > >> > >> > On Thu, Dec 13, 2012 at 11:55 AM, thefourtheye dIVi >> > <[email protected] <mailto:thechargi...@**gmail.com>> >> > wrote: >> > >> > Hi, >> > >> > I believe it is a very simple problem but still getting WA... :( >> > >> > Could you anyone please help me spotting the mistake? >> > >> > http://ideone.com/dAsYdK >> > -- >> >> -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msg/google-code/-/oby3yZGxHncJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
