Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8328776

Browse files
committed
add gas station
1 parent3a2c9c1 commit8328776

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

‎gas-station/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
##Guessing
12

2-
##TODO
3-
* write down thinking
3+
This problem is to find a UNIQUE station`i`, such that
44

5+
* SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) + SUM(gas[i .. end]) - SUM(cost[i .. end]) >= 0
6+
* SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) < 0
7+
8+
`SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) < 0` is to guarantee that the`i` is unique.
9+
10+
If`SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) < 0` and`SUM(gas[0 .. i-1]) - SUM(cost[0 .. i-1]) + SUM(gas[i .. end]) - SUM(cost[i .. end]) >= 0`, that is,`0 .. i-1` are all valid stations.
11+
12+
##Brute force
13+
14+
Just search through from`0` to`end`, find the valid`i`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp