Hi I have been in acm site for 1 week. so i am pretty novice.
i cannot understand the fact how you can use BFS or a Graph for instance in this problem? can anyone explain in brief? :D
PVM wrote:Hi I have been in acm site for 1 week. so i am pretty novice.
i cannot understand the fact how you can use BFS or a Graph for instance in this problem? can anyone explain in brief?
Problems 11195-11199 are not that easy. Sometimes, it is better to solve other problems first.
Here, it is not hard to see what the states are and how to go from one state to another state.
sclo wrote:
Here, it is not hard to see what the states are and how to go from one state to another state.
.. still i dont understand why it is meant by state. i tried to use insertion sort algorithm, but got WA. can you explain a bit more how I can use graph??
PVM wrote:
.. still i dont understand why it is meant by state. i tried to use insertion sort algorithm, but got WA. can you explain a bit more how I can use graph??
Let every permutation of the sequence be a vertex.. if a sequece can become another sequence with one operation, then it has an edge..
Hi! Can anybody tell me what is the expected execution time for an AC solution in the cases kindly given above? (about half of the total time for the complete input in the judge?)
any one can explain me how i need to solve this problem.. i totally dont understand how i need to solve it.. i tried insertion sort on it.. but got WA. and how i can use BFS on it... any one care to explain me.. thanks in advance
This is from a contest of brute force. You insert the starting position into a queue. For each position at the front of the queue, insert every possible unvisited move into the back of the queue.
For the first sample input, you can solve it in one move by -3 moving to 4's left.
The second is already solved.
The third can be solved by -4 moving to 5's left.
The fourth has no female digits so no moves are possible.
The fifth can be solved by
2 -8 -4 5 6 7 3 -1
-1 moving to 2's left
-1 2 -8 -4 5 6 7 3
-8 moving to 3's left
-1 2 -4 5 6 7 -8 3
3 moving to -4's left
-1 2 3 -4 5 6 7 -8
i dont understand how can i keep track of the point of the last visited... and i tried queue.. i tried to place the digit that was not in sorted form in the queue. than i searched where the index is value is..and than replaced it if the sum is prime..
i also tried to solve it via permutation. i got the unique permutation of 2 pairs i.e. keeping in mind that the sum should be a prime.
but still the code was WA. for some of the input given above.. my code works but for some it does not..
I use a queue for the BFS. Every reachable unvisited state from the current state is marked as visited and pushed onto the back of the queue. Note the explanation I posted for all the reachable states starting from 2 -8 -4 5 6 7 3 -1
Check input and AC output for thousands of problems on uDebug!