-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler83.c
More file actions
84 lines (75 loc) · 1.52 KB
/
Copy patheuler83.c
File metadata and controls
84 lines (75 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
/* dijkstra, rewrite with spfa...*/
/* dx, dy两个向量*/
#define MAX 80
char flag[MAX][MAX]={0};
unsigned int num[MAX][MAX];
unsigned int total[MAX][MAX]={0};
struct matrix{
int x;
int y;
} t;
struct matrix search()
{
struct matrix k;
int i, j, max=999999999;
for (i=0; i<MAX; i++) {
for (j=0; j<MAX; j++) {
if ((flag[i][j] == 0) && (total[i][j] <= max)) {
k.x = i;
k.y = j;
max = total[i][j];
}
}
}
return k;
}
void draw(struct matrix k, struct matrix p) {
int t;
if (p.x>=0 && p.x<MAX && p.y>=0 && p.y<MAX) {
t = total[k.x][k.y] + num[p.x][p.y];
if (t < total[p.x][p.y]) {
total[p.x][p.y] = t;
}
}
}
void remap(struct matrix k)
{
struct matrix p;
p.x = k.x-1;
p.y = k.y;
draw(k, p);
p.x = k.x+1;
p.y = k.y;
draw(k, p);
p.x = k.x;
p.y = k.y-1;
draw(k, p);
p.x = k.x;
p.y = k.y+1;
draw(k, p);
}
int main()
{
int i, j;
for (i=0; i<MAX; i++) {
for (j=0; j<MAX; j++) {
total[i][j] = ~total[i][j];
scanf("%d", &num[i][j]);
if (j==MAX-1) {
scanf("\n");
}
else {
scanf(",");
}
}
}
total[0][0] = num[0][0];
while (flag[MAX-1][MAX-1] == 0) {
t = search();
remap(t);
flag[t.x][t.y] = 1;
}
printf("%d\n", total[MAX-1][MAX-1]);
return 0;
}