Created
December 15, 2013 07:37
-
-
Save hakatashi/7970073 to your computer and use it in GitHub Desktop.
JOI2013年度予選問題3。
This file contains hidden or 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
#include <iostream> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main() { | |
int W, H, N, X[1000], Y[1000]; | |
short int dp[1000][1000]; | |
std::cin >> W >> H >> N; | |
for (int i = 0; i < N; i++) { | |
std::cin >> X[i] >> Y[i]; | |
} | |
for (int i = 0; i < 1000; i++) { | |
for (int j = 0; j < 1000; j++) { | |
if ( i==0 && j==0 ) { | |
dp[0][0] = 0; | |
} else if (j==0) { | |
dp[i][j] = dp[i-1][j] + 1; | |
} else if (i==0) { | |
dp[i][j] = dp[i][j-1] + 1; | |
} else { | |
dp[i][j] = dp[i-1][j-1] + 1; | |
} | |
} | |
} | |
int ans = 0; | |
for (int i = 1; i < N; i++) { | |
ans += ((X[i]-X[i-1])*(Y[i]-Y[i-1])>0)?((abs(X[i]-X[i-1])>abs(Y[i]-Y[i-1]))?abs(X[i]-X[i-1]):abs(Y[i]-Y[i-1])):(abs(X[i]-X[i-1]) + abs(Y[i]-Y[i-1])); | |
} | |
std::cout << ans << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment