Created
May 14, 2015 00:33
-
-
Save knuu/3e2ab6c4848bbff3821f to your computer and use it in GitHub Desktop.
SRM659 div.2 500 PublicTransit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PublicTransit { | |
public: | |
int minimumLongestDistance(int R, int C) { | |
int ret = 200; | |
for (int i = 0; i < R*C; i++) { | |
for (int j = 0; j < R*C; j++) { | |
int dist[110][110]; | |
for (int k = 0; k < R*C; k++) { | |
for (int l = 0; l < R*C; l++) { | |
int i1 = k/C, j1 = k%C, i2 = l/C, j2 = l%C; | |
dist[k][l] = abs(i1-i2)+abs(j1-j2); | |
} | |
} | |
dist[i][j] = 0; | |
dist[j][i] = 0; | |
for (int n = 0; n < R*C; n++) { | |
for (int m = 0; m < R*C; m++) { | |
dist[n][m] = min(dist[n][m], min(dist[n][i] + dist[j][m], dist[n][j] + dist[i][m])); | |
} | |
} | |
int ansi = 0; | |
for (int k = 0; k < R*C; k++) { | |
for (int l = 0; l < R*C; l++) { | |
ansi = max(ansi, dist[k][l]); | |
} | |
} | |
ret = min(ret, ansi); | |
} | |
} | |
return ret; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment