您的位置:首页 > 其它

hdu1010——Tempter of the Bone

2010-08-22 01:08 246 查看
#include<stdio.h>

#include<string.h>

#include<math.h>

#define maxv 10

int

dir[

4
][

2
]={{-

1
,

0
},{

1
,

0
},{

0
,-

1
},{

0
,

1
}};



char

g[

maxv][

maxv];



int

m,

n,

t;



int

escape;



int

scx,

scy;



int

outx,

outy;



int

sum;



void

dfs(

int

x,

int

y,

int

step)

{



int

i,

temp,

sx,

sy;



if

(

x==

outx&&

y==

outy&&

step==

t)


escape=

1
;



if

(

escape)//可以出去,返回!




return

;



if

(

step>

t)/走的步数大于时间限制,返回!




return

;



if

(

sum+

1
<

t-

step)//能走的地方小于必要步数,返回!




return

;



for

(

i=

0
;

i<

4
;

i++)

{


sx=

x+

dir[

i][

0
];


sy=

y+

dir[

i][

1
];



if

(

g[

sx][

sy]!=

'X'
&&

sx>=

0
&&

sy>=

0
&&

sx<

n&&

sy<

m)

{


g[

sx][

sy]=

'X'
;

sum--;


dfs(

sx,

sy,

step+

1
);


g[

sx][

sy]=

'.'
;

sum++;

}

}

}



main

()

{



int

i,

j,

k;



while

(

scanf(

"%d%d%d"
,&

n,&

m,&

t)!=

EOF)

{



if

(

n==

0
&&

m==

0
&&

t==

0
)



break

;



else



{


sum=

0
;



for

(

i=

0
;

i<

n;

i++)


scanf(

"%s"
,&

g[

i]);



for

(

i=

0
;

i<

n;

i++)



for

(

j=

0
;

j<

m;

j++)

{



if

(

g[

i][

j]==

'D'
)

{


outx=

i;

outy=

j;

}



else if

(

g[

i][

j]==

'S'
)

{


scx=

i;

scy=

j;

}



else if

(

g[

i][

j]==

'.'
)


sum++;

}



if

(

sum+

1
<

t)

{


printf(

"NO/n"
);



continue

;

}



if

((

abs(

outx-

scx)+

abs(

outy-

scy))%

2
!=

t%

2
)//奇偶数判断!不可少!

{


printf(

"NO/n"
);



continue

;

}


escape=

0
;


g[

scx][

scy]=

'X'
;


dfs(

scx,

scy,

0
);



if

(

escape)


printf(

"YES/n"
);



else


printf(

"NO/n"
);

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: