独轮车 推车的人脑子绕不过弯来 导致我写了好久

#include<stdio.h>
#include<queue>
using namespace std;
queue<int> row;
queue<int> col;
queue<int> fangxiang;
queue<int> yanse;
char maze[20][20];
int state[20][20][5][4];
int flag;
int x0,y0,x1,y1,x2,y2;
int num;
char dir0,colour0,colour1,colour2;
int c0,c1,c2,d0,d1;
int col_change();
int die_change1();
int die_change2();
void init();
void input();
int search();


int main()
{
flag=1;
input();
init();
while(flag==1)
{
num=search();
}
printf("%d\n",num-1);
return 0;
}


void input()
{
int i,j;

scanf("%d %d %c %c\n",&x0,&y0,&colour1,&dir0);
scanf("%d %d %c\n",&x2,&y2,&colour2);
x0=x0-1;
y0=y0-1;
x2=x2-1;
y2=y2-1;

for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
scanf("%c",&maze[i][j]);
}
if(i<19)
{
scanf("\n");
}
}

}


int col_change()
{
if(c1+1<5)
{
return c1+1;
}
else
{
return 0;
}
}


int die_change1()
{
if(d1+1<4)
{
return d1+1;
}
else
{
return 0;
}
}


int die_change2()
{
if(d1-1>=0)
{
return d1-1;
}
else
{
return 3;
}
}


void init()
{
if(colour1=='R')
{
c0=0;
}
else if(colour1=='Y')
{
c0=1;
}
else if(colour1=='B')
{
c0=2;
}
else if(colour1=='W')
{
c0=3;
}
else if(colour1=='G')
{
c0=4;
}
if(colour2=='R')
{
c2=0;
}
else if(colour2=='Y')
{
c2=1;
}
else if(colour2=='B')
{
c2=2;
}
else if(colour2=='W')
{
c2=3;
}
else if(colour2=='G')
{
c2=4;
}
if(dir0=='E')
{
d0=0;
}
else if(dir0=='S')
{
d0=1;
}
else if(dir0=='W')
{
d0=2;
}
else if(dir0=='N')
{
d0=3;
}
state[x0][y0][c0][d0]=1;
row.push(x0);
col.push(y0);
yanse.push(c0);
fangxiang.push(d0);
}
int search()
{
x1=row.front();
row.pop();
y1=col.front();
col.pop();
c1=yanse.front();
yanse.pop();
d1=fangxiang.front();
fangxiang.pop();

if(maze[x1+1][y1]=='.'&&d1==1&&state[x1+1][y1][col_change()][d1]==0&&x1+1<20)
{


state[x1+1][y1][col_change()][d1]=state[x1][y1][c1][d1]+1;

if(x1+1==x2&&y1==y2&&col_change()==c2)
{
flag=0;
return(state[x1][y1][c1][d1]+1);
}
row.push(x1+1);
   col.push(y1);
   yanse.push(col_change());
   fangxiang.push(d1);
}
if(maze[x1][y1+1]=='.'&&d1==0&&state[x1][y1+1][col_change()][d1]==0&&y1+1<20)
{
state[x1][y1+1][col_change()][d1]=state[x1][y1][c1][d1]+1;

if(x1==x2&&y1+1==y2&&col_change()==c2)
{
flag=0;
return(state[x1][y1][c1][d1]+1);
}
row.push(x1);
   col.push(y1+1);
   yanse.push(col_change());
   fangxiang.push(d1);
}
if(maze[x1-1][y1]=='.'&&d1==3&&state[x1-1][y1][col_change()][d1]==0&&x1-1>=0)
{

state[x1-1][y1][col_change()][d1]=state[x1][y1][c1][d1]+1;

if(x1-1==x2&&y1==y2&&col_change()==c2)
{
flag=0;
return(state[x1][y1][c1][d1]+1);
}
row.push(x1-1);
   col.push(y1);
   yanse.push(col_change());
   fangxiang.push(d1);
}
if(maze[x1][y1-1]=='.'&&d1==2&&state[x1][y1-1][col_change()][d1]==0&&y1-1>=0)
{
state[x1][y1-1][col_change()][d1]=state[x1][y1][c1][d1]+1;

if(x1==x2&&y1-1==y2&&col_change()==c2)
{
flag=0;
return(state[x1][y1][c1][d1]+1);
}
row.push(x1);
   col.push(y1-1);
   yanse.push(col_change());
   fangxiang.push(d1);
}
if(state[x1][y1][c1][die_change1()]==0)
{
state[x1][y1][c1][die_change1()]=state[x1][y1][c1][d1]+1;
row.push(x1);
   col.push(y1);
   yanse.push(c1);
   fangxiang.push(die_change1());
}
if(state[x1][y1][c1][die_change2()]==0)
{
state[x1][y1][c1][die_change2()]=state[x1][y1][c1][d1]+1;
row.push(x1);
   col.push(y1);
   yanse.push(c1);
   fangxiang.push(die_change2());
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值