水题。
1 #include <cstring> 2 #include <cstdio> 3 #include <string> 4 #include <iostream> 5 #include <algorithm> 6 #include <vector> 7 #include <queue> 8 #include <cmath> 9 using namespace std; 10 #define INF 100000000 11 int flag[1001][1001]; 12 double dis[1001][1001]; 13 int main() 14 { 15 int i,j,n,m,k,x,y; 16 double temp; 17 scanf("%d%d%d",&n,&m,&k); 18 for(i = 1;i <= k;i ++) 19 { 20 scanf("%d%d",&x,&y); 21 flag[x][y] = 1; 22 } 23 for(i = 0;i <= n;i ++) 24 { 25 for(j = 0;j <= m;j ++) 26 dis[i][j] = INF; 27 } 28 dis[0][0] = 0; 29 temp = 100*sqrt(2.0); 30 for(i = 0;i <= n;i ++) 31 { 32 for(j = 0;j <= m;j ++) 33 { 34 if(i-1 >= 0) 35 dis[i][j] = min(dis[i-1][j]+100,dis[i][j]); 36 if(j-1 >= 0) 37 dis[i][j] = min(dis[i][j-1]+100,dis[i][j]); 38 if(flag[i][j]) 39 dis[i][j] = min(dis[i-1][j-1]+temp,dis[i][j]); 40 } 41 } 42 printf("%.0lf ",dis[n][m]); 43 return 0; 44 }