-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb2de98
commit 62156e2
Showing
4 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
const int INF = INT_MAX /2; | ||
|
||
struct node | ||
{ | ||
int X; | ||
int Y; | ||
int T; | ||
|
||
node(int x, int y,int t) | ||
{ | ||
X=x; | ||
Y=y; | ||
T=t; | ||
} | ||
}; | ||
|
||
|
||
//int dd[105][105][4]; | ||
int main() | ||
{ | ||
int n=0, m=0, q; | ||
int i, j; | ||
int sx, sy, ex, ey, tx=0, ty=0, tt; | ||
int x, y, time; | ||
|
||
freopen("getaway_UVA949.in", "r", stdin); | ||
freopen("getaway_UVA949.out", "w", stdout); | ||
|
||
vector<int> dx = {0, 0, 1, -1}; | ||
vector<int> dy = {1, -1, 0, 0}; | ||
|
||
|
||
while (true) | ||
{ | ||
cin >> n >> m; | ||
|
||
if (!cin.good()) | ||
{ | ||
break; | ||
} | ||
|
||
//不允许通过的路 | ||
vector<vector<vector<int>>> dd(n+1,vector<vector<int>>(m+1,vector<int>(4,1))); | ||
vector<vector<set<int>>> monitor(n+1,vector<set<int>>(m+1)); | ||
|
||
cin >> q; | ||
|
||
while (q--) | ||
{ | ||
cin >> sx >> sy >> ex >> ey; | ||
|
||
for (j = 0; j < 4; j++) | ||
{ | ||
tx = sx + dx[j], ty = sy + dy[j]; | ||
|
||
if (tx == ex && ty == ey) | ||
{ | ||
dd[sx][sy][j] = 0; //can't allow | ||
} | ||
} | ||
} | ||
cin >> q; | ||
while (q--) | ||
{ | ||
cin >> time >> sx >> sy; | ||
monitor[sx][sy].insert(time); | ||
} | ||
|
||
if (n == 1 && m == 1) | ||
{ | ||
cout <<"0\n"; | ||
continue; | ||
} | ||
|
||
queue<node> q; | ||
q.push(node(0,0,0)); | ||
|
||
|
||
vector<vector<int>> dist(n+1,vector<int>(m+1,INF)); //dist[x][y]代表到达x,y最小时间 | ||
// int dist[105][105] = {}; | ||
// memset(dist, 63, sizeof(dist)); | ||
|
||
dist[0][0] = 0; | ||
|
||
|
||
while (!q.empty()) | ||
{ | ||
|
||
x = q.front().X; | ||
y = q.front().Y; | ||
time = q.front().T; | ||
q.pop(); | ||
|
||
++time; | ||
|
||
for (i = 0; i < 4; ++i) | ||
{ | ||
if (dd[x][y][i] == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
tx = x + dx[i]; | ||
ty = y + dy[i]; | ||
|
||
if (tx < 0 || ty < 0 || tx >= n || ty >= m) | ||
{ | ||
continue; | ||
} | ||
tt = time; | ||
|
||
//while (monitor[tx][ty].find(tt) != monitor[tx][ty].end()) | ||
while (monitor[tx][ty].count(tt) != 0) | ||
{ | ||
++tt; | ||
} | ||
|
||
if (tt < dist[tx][ty]) | ||
{ | ||
dist[tx][ty] = tt; | ||
q.push(node(tx,ty,tt)); | ||
} | ||
} | ||
} | ||
cout << dist[n - 1][m - 1] << '\n'; | ||
} | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int dd[105][105][4]; | ||
int dx[] = {0,0,1,-1}; | ||
int dy[] = {1,-1,0,0}; | ||
int main() { | ||
|
||
freopen("getaway_UVA949.in", "r", stdin); | ||
freopen("getaway_UVA949.out", "w", stdout); | ||
|
||
int n, m, q; | ||
int i, j, k; | ||
int sx, sy, ex, ey, tx, ty, tt; | ||
int x, y, time; | ||
while(scanf("%d %d", &n, &m) == 2) { | ||
for(i = 0; i < n; i++) | ||
for(j = 0; j < m; j++) | ||
for(k = 0; k < 4; k++) | ||
dd[i][j][k] = 1; | ||
set<int> monitor[105][105]; | ||
scanf("%d", &q); | ||
while(q--) { | ||
scanf("%d %d %d %d", &sx, &sy, &ex, &ey); | ||
for(j = 0; j < 4; j++) { | ||
tx = sx+dx[j], ty = sy+dy[j]; | ||
if(tx == ex && ty == ey) | ||
dd[sx][sy][j] = 0;//can'c allow | ||
} | ||
} | ||
scanf("%d", &q); | ||
while(q--) { | ||
scanf("%d %d %d", &time, &sx, &sy); | ||
monitor[sx][sy].insert(time); | ||
} | ||
queue<int> X, Y, T; | ||
X.push(0), Y.push(0), T.push(0); | ||
int dist[105][105] = {}; | ||
memset(dist, 63, sizeof(dist)); | ||
dist[0][0] = 0; | ||
if(n == 1 && m == 1) { | ||
puts("0"); | ||
continue; | ||
} | ||
while(!X.empty()) { | ||
x = X.front(), X.pop(); | ||
y = Y.front(), Y.pop(); | ||
time = T.front(), T.pop(); | ||
time++; | ||
for(i = 0; i < 4; i++) { | ||
if(dd[x][y][i] == 0) continue; | ||
tx = x+dx[i], ty = y+dy[i]; | ||
if(tx < 0 || ty < 0 || tx >= n || ty >= m) | ||
continue; | ||
tt = time; | ||
while(monitor[tx][ty].find(tt) != monitor[tx][ty].end()) | ||
tt++; | ||
if(tt < dist[tx][ty]) { | ||
dist[tx][ty] = tt; | ||
X.push(tx), Y.push(ty), T.push(tt); | ||
} | ||
} | ||
} | ||
printf("%d\n", dist[n-1][m-1]); | ||
} | ||
return 0; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
0 | ||
2 | ||
4 | ||
6 | ||
8 | ||
10 | ||
12 | ||
14 | ||
16 | ||
18 | ||
20 | ||
19 | ||
13 | ||
27 | ||
11 | ||
22 | ||
16 | ||
31 | ||
29 | ||
24 | ||
9 | ||
21 | ||
22 | ||
13 | ||
33 | ||
26 | ||
32 | ||
17 | ||
37 | ||
17 | ||
26 | ||
29 | ||
27 | ||
11 | ||
21 | ||
31 | ||
10 | ||
14 | ||
32 | ||
18 | ||
16 | ||
27 | ||
18 | ||
21 | ||
15 | ||
8 | ||
25 | ||
20 | ||
10 | ||
18 | ||
20 | ||
27 | ||
6 | ||
21 | ||
32 | ||
18 | ||
31 | ||
27 | ||
25 | ||
18 | ||
6 | ||
26 | ||
15 | ||
27 | ||
18 | ||
25 | ||
30 | ||
26 | ||
24 | ||
7 | ||
20 | ||
15 | ||
13 | ||
23 | ||
25 | ||
22 | ||
23 | ||
25 | ||
21 | ||
25 | ||
21 | ||
16 | ||
23 | ||
19 | ||
17 | ||
8 | ||
30 | ||
32 | ||
21 | ||
23 | ||
23 | ||
32 | ||
19 | ||
18 | ||
16 | ||
26 | ||
19 | ||
28 | ||
22 | ||
24 |