hdu 4741 2013杭州赛区网络赛 dfs ***

时间:2023-12-31 14:43:56

起点忘记录了,一直wa

代码写的很整齐,看着很爽

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
int dir[][]={,,,,,-,-,};
bool vis1[MAXN][MAXN];
bool vis2[MAXN][MAXN];
void dfs(int dx,int dy,int dd,int tx,int ty,int td)
{
if(dx==tx&&dy==ty)
{
printf("%d %d\n",dx,dy);
return;
}
bool f1=,f2=;
int ndd=dd;
int ndx=dx+dir[dd][];
int ndy=dy+dir[dd][];
if(ndx<||ndx>=n||ndy<||ndy>=n||vis1[ndx][ndy]) ndd=(dd+)%;
ndx=dx+dir[ndd][];
ndy=dy+dir[ndd][];
if(ndx<||ndx>=n||ndy<||ndy>=n||vis1[ndx][ndy])
{
f1=;
ndx=dx,ndy=dy,ndd=dd;
} int ntd=td;
int ntx=tx+dir[td][];
int nty=ty+dir[td][];
if(ntx<||ntx>=n||nty<||nty>=n||vis2[ntx][nty]) ntd=(td-+)%;
ntx=tx+dir[ntd][];
nty=ty+dir[ntd][];
if(ntx<||ntx>=n||nty<||nty>=n||vis2[ntx][nty])
{
f2=;
ntx=tx,nty=ty,ntd=td;
}
if(f1&&f2)
{
printf("-1\n");
return;
}
vis1[ndx][ndy]=;
vis2[ntx][nty]=; dfs(ndx,ndy,ndd,ntx,nty,ntd);
}
int main()
{
int i,j,k,ca=;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
int dx,dy,dd,tx,ty,td;
int tot=;
while(scanf("%d",&n)!=EOF&&n)
{
cl(vis1);
cl(vis2);
scanf("%d%d%d",&dx,&dy,&dd);
scanf("%d%d%d",&tx,&ty,&td);
vis1[dx][dy]=;
vis2[tx][ty]=;
dfs(dx,dy,dd,tx,ty,td);
}
}