比赛 |
20120808 |
评测结果 |
EWEEWEEEEE |
题目名称 |
鬼屋惊魂 |
最终得分 |
0 |
用户昵称 |
Truth.Cirno |
运行时间 |
1.227 s |
代码语言 |
C++ |
内存使用 |
26.99 MiB |
提交时间 |
2012-08-08 12:09:30 |
显示代码纯文本
- #include <cstdio>
- using namespace std;
-
- const int RUL[5][2]={{0,-1},{0,1},{-1,0},{1,0},{0,0}};
-
- int n,que[1000000][3][2],deep[1000000],tar[3][2],tail,head,c;
- char map[20][20];
-
- bool check(void)
- {
- int i;
- for (i=0;i<n;i++)
- if (tar[i][0]!=que[head][i][0]||tar[i][1]!=que[head][i][1])
- return(0);
- return(1);
- }
-
- void go(void)
- {
- int t,t2,i[3],x[3],y[3];
- bool done=false,flag;
- while (!done&&head>=tail)
- {
- for (i[0]=0;i[0]<5;i[0]++)
- {
- if (n>1)
- {
- for (i[1]=0;i[1]<5;i[1]++)
- {
- if (n>2)
- {
- for (i[2]=0;i[2]<5;i[2]++)
- {
- /**/
- for (t=0;t<n;t++)
- {
- x[t]=que[tail][t][0]+RUL[i[t]][0];
- y[t]=que[tail][t][1]+RUL[i[t]][1];
- }
- flag=true;
- for (t=0;t<n;t++)
- if (x[t]>=0&&y[t]>=0&&map[x[t]][y[t]]=='#')
- {
- flag=false;
- break;
- }
- if (!flag)
- continue;
- for (t=0;t<n;t++)
- for (t2=0;t2<n;t2++)
- if (t!=t2&&que[tail][t][0]==x[t2]&&que[tail][t][1]==y[t2]&&que[tail][t2][0]==x[t]&&que[tail][t2][1]==y[t])
- {
- flag=false;
- break;
- }
- if (!flag)
- continue;
- head++;
- for (t=0;t<n;t++)
- {
- que[head][t][0]=x[t];
- que[head][t][1]=y[t];
- }
- deep[head]=deep[tail]+1;
- if (check())
- return;
- /**/
- }
- }
- else
- {
- /**/
- for (t=0;t<n;t++)
- {
- x[t]=que[tail][t][0]+RUL[i[t]][0];
- y[t]=que[tail][t][1]+RUL[i[t]][1];
- }
- flag=true;
- for (t=0;t<n;t++)
- if (map[x[t]][y[t]]=='#')
- {
- flag=false;
- break;
- }
- if (!flag)
- continue;
- for (t=0;t<n;t++)
- for (t2=0;t2<n;t2++)
- if (t!=t2&&que[tail][t][0]==x[t2]&&que[tail][t][1]==y[t2]&&que[tail][t2][0]==x[t]&&que[tail][t2][1]==y[t])
- {
- flag=false;
- break;
- }
- if (!flag)
- continue;
- head++;
- for (t=0;t<n;t++)
- {
- que[head][t][0]=x[t];
- que[head][t][1]=y[t];
- }
- deep[head]=deep[tail]+1;
- if (check())
- return;
- /**/
- }
- }
- }
- else
- {
- /**/
- for (t=0;t<n;t++)
- {
- x[t]=que[tail][t][0]+RUL[i[t]][0];
- y[t]=que[tail][t][1]+RUL[i[t]][1];
- }
- flag=true;
- for (t=0;t<n;t++)
- if (map[x[t]][y[t]]=='#')
- {
- flag=false;
- break;
- }
- if (!flag)
- continue;
- for (t=0;t<n;t++)
- for (t2=0;t2<n;t2++)
- if (t!=t2&&que[tail][t][0]==x[t2]&&que[tail][t][1]==y[t2]&&que[tail][t2][0]==x[t]&&que[tail][t2][1]==y[t])
- {
- flag=false;
- break;
- }
- if (!flag)
- continue;
- head++;
- for (t=0;t<n;t++)
- {
- que[head][t][0]=x[t];
- que[head][t][1]=y[t];
- }
- deep[head]=deep[tail]+1;
- if (check())
- return;
- /**/
- }
- }
- tail++;
- }
- }
-
- int main(void)
- {
- freopen("jumby.in","r",stdin);
- freopen("jumby.out","w",stdout);
- int i,j,y,x;
- scanf("%d %d %d\n",&y,&x,&n);
- while (x!=0&&y!=0&&n!=0)
- {
- for (i=0;i<x;i++)
- scanf("%[^\n]\n",&map[i]);
- for (i=0;i<x;i++)
- for (j=0;j<y;j++)
- if (map[i][j]=='a')
- {
- que[0][0][0]=i;
- que[0][0][1]=j;
- }
- else if (map[i][j]=='b')
- {
- que[0][1][0]=i;
- que[0][1][1]=j;
- }
- else if (map[i][j]=='c')
- {
- que[0][2][0]=i;
- que[0][2][1]=j;
- }
- else if (map[i][j]=='A')
- {
- tar[0][0]=i;
- tar[0][1]=j;
- }
- else if (map[i][j]=='B')
- {
- tar[1][0]=i;
- tar[1][1]=j;
- }
- else if (map[i][j]=='C')
- {
- tar[2][0]=i;
- tar[2][1]=j;
- }
- go();
- printf("%d\n",deep[head]);
- scanf("%d %d %d\n",&y,&x,&n);
- }
- return(0);
- }