| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
poj3009为什么撞到石头后,把1变成0,然后递归dfs,后又要把0还原成1?poj3009为什么撞到石头后,把1变成0,然后递归dfs,后又要把0还原成1?
主要dfs代码如下
for (int i = 0; i < 4; i++){
xt = x;
yt = y;
while ( (0<=xt&&xt<h) && (0<=yt&&yt<w) // 向某个方向一直飞啊飞~
&& (map[xt][yt] == 0 or map[xt][yt] == 2)){//vacant square or start
xt += dh[i];
yt += dw[i];
}
if (0<=xt&&xt<h && 0<=yt&&yt<w && map[xt][yt] == 3){ // 飞过(到)目标了
if (times+1 < ans){
ans = times+1;
}
}
else if (!(xt-dh[i]==x && yt-dw[i]==y) // 必须有空地才能飞啊,待在原地不算啊
&& 0<=xt&&xt<h && 0<=yt&&yt<w && map[xt][yt] == 1){ // blocks
map[xt][yt] = 0;
dfs(xt-dh[i], yt-dw[i], times+1);
map[xt][yt] = 1; //此处
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator