ChrisVilches / Algorithms

Solutions for competitive programming problems in various online judges such as Kattis, SPOJ, URI Online Judge, etc.
5 stars 0 forks source link

Cornering at Poles (backtracking) very rare corner case where the algorithm fails discovered #30

Closed ChrisVilches closed 1 year ago

ChrisVilches commented 1 year ago

These two cases. The first one is OK, but the second one fails.

5 120 15
70 115
70 -80
70 -270
70 -460
70 -650

6 120 15
70 305
70 115
70 -80
70 -270
70 -460
70 -650

The correct answer should be (obtained using Dijkstra's algorithm):

547.69077435
927.69077435

(These correct answers were confirmed using multiple solutions from Aizu judge)

But the backtracking implementation returns the following results:

547.69077435
0.00000000

The cause: The backtracking algorithm incorrectly assumes that every pole is visited at most once, but this case actually needs a second visit in order to get to the goal. It seems that in the official test data (100 cases in total) this never happened, so it gets accepted anyway.

ChrisVilches commented 1 year ago

What to do:

Either comment the source code and indicate that it's deprecated and doesn't work.

Or, fix the code so that it works!

ChrisVilches commented 1 year ago

Commented here: https://github.com/ChrisVilches/Algorithms/commit/f0add904b8f0002879ddb95ab6e5fa6913acc7bb

I won't fix the code, but I commented the source. The program still gets AC so I'll just leave it there.