-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSW expert-보급로.cpp.txt
75 lines (63 loc) · 1.21 KB
/
SW expert-보급로.cpp.txt
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
#include<iostream>
#include<vector>
#include<fstream>
#include<string>
#include<queue>
#include<cstdio>
#include<functional>
using namespace std;
int arr[101][101];
bool visit[101][101];
int dx[4] = { -1,1,0,0 };
int dy[4] = { 0,0,-1,1 };
struct my_struct {
int x, y, depth;
};
int main()
{
int testCase,countT;
countT = 1;
cin >> testCase;
while (testCase != 0)
{
priority_queue < pair<int, int>, vector<pair<int, int> >, greater<pair<int, int >>> pq;
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
int num;
scanf_s("%1d", &num);
arr[i][j] = num;
visit[i][j] = false;
}
}
pq.push(make_pair(0, 0));
visit[0][0] = true;
while (!pq.empty())
{
int depth = pq.top().first;
int x = pq.top().second/N;
int y = pq.top().second % N;
pq.pop();
if (x == N-1 && y == N-1)
{
cout << "#" << countT++ << " " << depth << endl;
break;
}
for (int i = 0; i < 4; i++)
{
int Gx = x + dx[i];
int Gy = y + dy[i];
if (Gx >= 0 && Gx < N&&Gy >= 0 && Gy < N && !visit[Gx][Gy])
{
visit[Gx][Gy] = true;
pq.push(make_pair(depth + arr[Gx][Gy],(Gx*N+Gy)));
}
}
}
testCase--;
}
return 0;
}