您的位置:首页 > 其它

(HDU1010)Tempter of the Bone

2016-09-16 16:29 351 查看
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1010

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<ctime>
#include<fstream>
#include<iomanip>
using namespace std;

#define M 105

int n,m,t,si,sj,ei,ej,c,wall;
char ma[M][M];
int dir[4][2]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void DFS(int x, int y, int time)
{
if (x<=0||x>n||y<=0||y>m) return;
if (c) return;
if (x == ei && y == ej && time == t)
{
if(time == t)
c = 1;
return;
}

int temp = (t - time) - abs(x - ei) - abs(y - ej);
if(temp<0 || temp & 1)  return;

for (int i=0;i<4;i++)
{
int x1=x+dir[i][0];
int y1=y+dir[i][1];
if (ma[x1][y1]!='X')
{
ma[x1][y1]='X';
DFS(x1, y1,time+1);
ma[x1][y1]='.';
}
}
return;
}

int main()
{
while (cin>>n>>m>>t)
{
if(n==0&&m==0&&t==0) break;
wall = 0;
for (int i = 1; i<=n; i++)
{
for (int j = 1; j<=m; j++)
{
cin>>ma[i][j];
if (ma[i][j] == 'S')
{
si = i;
sj = j;
}
if (ma[i][j] == 'D')
{
ei = i;
ej = j;
}
if (ma[i][j] == 'X')
wall ++;
}
}
c = 0;
ma[si][sj] = 'X';

if (n * m - wall <= t)
{
cout<<"NO"<<endl;
continue;
}
DFS(si, sj, 0);
if (c)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: