Comments (1)
Just had a quick look over the Java.
I think the first step you would want to calculate the shortest distance from start
to finish
using Dijkstra for example to give you an upper bound.vNow you know that there could be a better possible solution, depending on how you represent data you could store the shortest path to each point from start
so you know how long it takes to get from start
to every node.
Because you know the current upper bound; go to each wall and calculate distance from wall
to end
without crossing any other walls again. You will get an answer wallToEndDistance
which you will need to add to startToWallDistance
. Compare totalDistance
to currentMin
. You only need to calculate the algorithm for the starting node, and every wall that startToWallDistance
< currentMin
. After you exhausted all possible walls you have the min, I think you were calculating DFS too many times as it was recursive but really distance calculations should only be called 1-30 times.
There is actually a way to do this using A* if you prefer to use that, the data structure used by A* may be more helpful.
It might be worth storing the nodes aa a data structure that contains x
y
isWall
and distance
, distance
= startToNode
, then also having a list of wall nodes. This way you can just refer to your list and see which wall you have not calculated all the shortest distance for. For weight you can just use isWall*100000 + 1
for example.
from google-foobar-help.
Related Issues (18)
- About doomsday_fuel challenge HOT 3
- Distract the guards HOT 6
- (I-Q)^-1 =? HOT 1
- Help wanted
- For test cases 3 and 10 f's columns do not match r's rows HOT 6
- How do you calculate inverse of matrix with fractions? HOT 2
- Add more Google Foobar Challenges!
- Some more to add (don't remember the names though)
- En Route Salute in one pass HOT 1
- doomsday_fuel issue HOT 1
- Distract the Trainers - Maximum Matching
- Failing one test on doomsday_fuel HOT 4
- Two-layer Dijkstra solution for prepare_the_bunnies_escape HOT 3
- Help ? (doomsday_fuel) HOT 13
- t
- Doomsday Fuel Python Test 8 HOT 29
- doomsday_fuel tests HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-foobar-help.