Skip to content

Commit e95d809

Browse files
committed
[uva] Add C++ solution for 10377 - Maze Traversal.
1 parent 604d89d commit e95d809

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

uva/10377-1.ans

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5 6 W

uva/10377-1.in

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1
2+
3+
7 8
4+
********
5+
* * * **
6+
* * *
7+
* * ** *
8+
* * * *
9+
* * **
10+
********
11+
2 4
12+
RRFLFF FFR
13+
FF
14+
RFFQ

uva/10377.cc

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// https://uva.onlinejudge.org/external/103/10377.pdf
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
using vs=vector<string>;
5+
int main(){
6+
ios::sync_with_stdio(0);
7+
cin.tie(0);
8+
int t,n,m,y,x,o,q;
9+
int dy[]={-1,0,1,0};
10+
int dx[]={0,1,0,-1};
11+
cin>>t;
12+
for(int T=0;T<t;T++){
13+
cin>>n>>m;
14+
string s;
15+
getline(cin,s);
16+
vs a(n);
17+
for(int i=0;i<n;i++){
18+
getline(cin,s);
19+
a[i]=s;
20+
}
21+
cin>>y>>x;
22+
getline(cin,s);
23+
y--;x--;
24+
o=0;q=0;
25+
for(;;){
26+
getline(cin,s);
27+
for(char c:s){
28+
if(c=='L')o=!o?3:o-1;
29+
else if(c=='R')o=o==3?0:o+1;
30+
else if(c=='F'){
31+
if(a[y+dy[o]][x+dx[o]]!='*'){y+=dy[o];x+=dx[o];}
32+
}else if(c=='Q'){q=1;break;}
33+
}
34+
if(q)break;
35+
}
36+
for(;;){
37+
getline(cin,s);
38+
if(s.empty())break;
39+
}
40+
if(T)cout<<"\n";
41+
cout<<y+1<<" "<<x+1<<" "<<"NESW"[o]<<"\n";
42+
}
43+
}

uva/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ There are solutions for the following
111111
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1277))
112112
1. [10369 - Arctic Network](10369.cc)
113113
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1310))
114+
1. [10377 - Maze Traversal](10377.cc)
115+
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1318))
114116
1. [10382 - Watering Grass](10382.cc)
115117
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1323))
116118
1. [10507 - Waking up brain](10507.cc)

0 commit comments

Comments
 (0)