For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...
why problem description so unclear ?
"A ship is destroyed if it moves to a cell that contais a rock."
again, "If an enemy ship reaches your ship, you are dead", then what will be if my ship move to a rock ?
if my ship can move to a rock, it should be told that "only enemy ship is destroyed if it moves to a cell that contais a rock."
and if my ship cannot move to a rock, it should be told that "If an enemy ship reaches your ship or your ship moves to a rock, you are dead",
please clarify me
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program
My code passed all of these testcases, but still WA. the problem statements says that less than 10 moves so 10th move is not correct ok?
can anybody help me?
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
Oh no! I'm a dead man!
Oh no! I'm a dead man!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
Oh no! I'm a dead man!
I'm the king of the Seven Seas!
Oh no! I'm a dead man!
Oh no! I'm a dead man!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
I'm the king of the Seven Seas!
Oh no! I'm a dead man!
I got it at last. I did a very nasty mistake in my dfs function. anyway, this is a very simple problem, so a simple dfs is enough, also I think this problem has so many vagueness because I got it with different answers for the posted testcases, especially for my own testcases.
I solved this problem with BFS But without the need of a visit array, would it make any difference if used it ??
and how can i use a map with the following key and value:
I solved this and got AC in 4 different ways:
DFS no visit set: 0.219 seconds
DFS with set<string> visit: 0.015 seconds
BFS no visit set: 0.342 seconds
BFS with set<string> visit: 0.015 seconds
Adding the visit set speeds up DFS and BFS. In DFS you should not remove a visited state when backtracking. It is not possible to reach the same state with a different number of moves.
You should use a set for visit instead of mapping to a bool. Then you can check if the state is in the set or not.
An array address is really a pointer, so you would need to make sure that the data you are pointing to is not changing. It is easier to use a string or vector and then the data instead of the pointer is pushed into the set.
Check input and AC output for thousands of problems on uDebug!
brianfry713 wrote:I solved this and got AC in 4 different ways:
DFS no visit set: 0.219 seconds
DFS with set<string> visit: 0.549 seconds
BFS no visit set: 0.342 seconds
BFS with set<string> visit: 0.015 seconds
Adding the visit set slows down DFS because it's impossible to reach the same state, however it speeds up BFS.
You should use a set for visit instead of mapping to a bool. Then you can check if the state is in the set or not.
An array address is really a pointer, so you would need to make sure that the data you are pointing to is not changing. It is easier to use a string or vector and then the data instead of the pointer is pushed into the set.
You are totally right
I changed my 2D array into a 1D vector and used "map<vector<int>,bool>" for the visit and and my timing became 0.016 - 11X times Faster -
Thank you brianfry713