/*
BFS
*/
#include
<
iostream
>
using
namespace
std;
int
N;
int
map[
11
][
11
];
int
x[
110
],y[
110
];
const
int
d[
4
][
2
]
=
{
1
,
0
,
0
,
1
,
-
1
,
0
,
0
,
-
1
};
const
char
*
ys
=
"
RTLB
"
;
int
make(
char
ch){
if
(ch
==
'
R
'
)
return
0
;
if
(ch
==
'
T
'
)
return
1
;
if
(ch
==
'
L
'
)
return
2
;
if
(ch
==
'
B
'
)
return
3
;
}
int
main()
{
char
s[
10
];
gets(s);
int
k
=
0
;
int
a,b;
int
h,t;
N
=
b
=
0
;
for
(
int
i
=
0
;i
<
strlen(s);
++
i)
if
(s[i]
!=
'
'
) k
=
k
*
10
+
s[i]
-
'
0
'
;
else
{
if
(
!
N){
N
=
a
=
k;
}
else
b
=
k;
k
=
0
;
}
if
(
!
N){
N
=
a
=
k;
}
else
b
=
k;
memset(map,
0
,
sizeof
(map));
if
(
!
b){
scanf(
"
%d%d
"
,
&
a,
&
b);
x[
1
]
=
a; y[
1
]
=
b;
for
(
int
i
=
1
;i
<
N;
++
i){
scanf(
"
%d%d
"
,
&
a,
&
b);
map[a][b]
=
1
;
}
printf(
"
%d %d\n
"
,x[
1
],y[
1
]);
h
=
t
=
1
;
while
(h
<=
t){
for
(
int
i
=
0
;i
<
4
;
++
i){
a
=
x[h]
+
d[i][
0
]; b
=
y[h]
+
d[i][
1
];
if
(map[a][b]){
t
++
;
x[t]
=
a; y[t]
=
b;
map[a][b]
=
0
;
printf(
"
%c
"
,ys[i]);
}
}
h
++
;
if
(h
>
t) printf(
"
.\n
"
);
else
printf(
"
,\n
"
);
}
}
else
{
h
=
t
=
1
;
x[
1
]
=
a; y[
1
]
=
b;
map[a][b]
=
1
;
while
(h
<=
t){
gets(s);
if
(s[
0
]
==
'
.
'
)
break
;
for
(
int
i
=
0
;i
<
strlen(s);
++
i)
if
(s[i]
==
'
,
'
)
break
;
else
{
a
=
x[h]
+
d[make(s[i])][
0
];
b
=
y[h]
+
d[make(s[i])][
1
];
if
(
!
map[a][b]){
t
++
;
x[t]
=
a;
y[t]
=
b;
map[a][b]
=
1
;
}
}
h
++
;
}
printf(
"
%d\n
"
,t);
for
(
int
i
=
1
;i
<=
10
;
++
i)
for
(
int
j
=
1
;j
<=
10
;
++
j)
if
(map[i][j])
printf(
"
%d %d\n
"
,i,j);
}
return
0
;
}
posted on 2009-05-28 13:27
xfstart07 阅读(158)
评论(0) 编辑 收藏 引用 所属分类:
代码库