题意:
给出一片森林
在这片森林里, 驴和虎从没见过对方, 因此一见面就吓尿了, 撒腿就跑
0 1 2 3代表四个方向, 没有特殊情况就按初始方向直直跑
不能继续向前了, 驴是只考虑向右, 而虎是只考虑向左
注意, 驴和虎都不能跑自己曾经跑过的地块!
AC代码:
#include
#include
#include
int lgrid[1234][1234];
int hgrid[1234][1234];
int t;
int success;
int lunremove;
int hunremove;
int ansx, ansy;
int main() {
while(scanf("%d", &t) != EOF && t) {
success = 0;
lunremove = 1;
hunremove = 1;
memset(lgrid, 0, sizeof(lgrid));
memset(hgrid, 0, sizeof(hgrid));
int ltx, lty, htx, hty;
int ltd, htd;
scanf("%d %d %d", 0 && lgrid[ltx][lty-1] != 1)
lty = lty - 1;
else if(ltx > 0 && lgrid[ltx-1][lty] != 1) {
ltx = ltx - 1;
ltd = 3;
}
else
lunremove = 0;
}
else if(ltd == 1 && lunremove == 1) {
if(ltx < t-1 && lgrid[ltx+1][lty] != 1)
ltx = ltx + 1;
else if(lty > 0 && lgrid[ltx][lty-1] != 1) {
lty = lty - 1;
ltd = 2;
}
else
lunremove = 0;
}
else if(ltd == 0 && lunremove == 1) {
if(lty < t-1 && lgrid[ltx][lty+1] != 1)
lty = lty + 1;
else if(ltx < t-1 && lgrid[ltx+1][lty] != 1) {
ltx = ltx + 1;
ltd = 1;
}
else
lunremove = 0;
}
else if(ltd == 3 && lunremove == 1) {
if(ltx > 0 && lgrid[ltx-1][lty] != 1)
ltx = ltx - 1;
else if(lty < t-1 && lgrid[ltx][lty+1] != 1) {
lty = lty + 1;
ltd = 0;
}
else
lunremove = 0;
}
if(htd == 2 && hunremove == 1) {
if(hty > 0 && hgrid[htx][hty-1] != 1)
hty = hty - 1;
else if(htx < t-1 && hgrid[htx+1][hty] != 1) {
htx = htx + 1;
htd = 1;
}
else
hunremove = 0;
}
else if(htd == 1 && hunremove == 1) {
if(htx < t-1 && hgrid[htx+1][hty] != 1)
htx = htx + 1;
else if(hty < t-1 && hgrid[htx][hty+1] != 1) {
hty = hty + 1;
htd = 0;
}
else
hunremove = 0;
}
else if(htd == 0 && hunremove == 1) {
if(hty < t-1 && hgrid[htx][hty+1] != 1)
hty = hty + 1;
else if(htx > 0 && hgrid[htx-1][hty] != 1) {
htx = htx - 1;
htd = 3;
}
else
hunremove = 0;
}
else if(htd == 3 && hunremove == 1) {
if(htx > 0 && hgrid[htx-1][hty] != 1)
htx = htx - 1;
else if(hty > 0 && hgrid[htx][hty-1] != 1) {
hty = hty - 1;
htd = 2;
}
else
hunremove = 0;
}
}
if(success == 1)
printf("%d %d\n", ansx, ansy);
else
printf("-1\n");
}
return 0;
}