比赛 |
NOIP2008集训模拟3 |
评测结果 |
AAWTTATTTA |
题目名称 |
移动骷髅 |
最终得分 |
40 |
用户昵称 |
zqzas |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 11:21:05 |
显示代码纯文本
#include <iostream>
#define MAXN 10
#define INF 999999999
using namespace std;
const int n=5;
int u,fei,ans,data[MAXN][MAXN];
void dfs(int now)
{
if (data[3][3]==2)
{
if (now<ans)
ans=now;
}
if (now>100)
return;
if (now>ans)
return;
int i,j,x,y;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
if (now==1)
fei=1;
if (data[i][j]==0)
continue;
for (x=1;x<i-1;x++)
if (data[x][j]!=0 && data[x+1][j]==0)
{
data[x+1][j]=data[i][j];
data[i][j]=0;
dfs(now+1);
data[i][j]=data[x+1][j];
data[x+1][j]=0;
}
for (x=i+2;x<=n;x++)
if (data[x][j]!=0 && x!=i && data[x-1][j]==0)
{
data[x-1][j]=data[i][j];
data[i][j]=0;
dfs(now+1);
data[i][j]=data[x-1][j];
data[x-1][j]=0;
}
for (y=1;y<j-1;y++)
if (data[i][y]!=0 && data[i][y+1]==0)
{
data[i][y+1]=data[i][j];
data[i][j]=0;
dfs(now+1);
data[i][j]=data[i][y+1];
data[i][y+1]=0;
}
for (y=j+2;y<=n;y++)
if (data[i][y]!=0 && data[i][y-1]==0)
{
data[i][y-1]=data[i][j];
data[i][j]=0;
dfs(now+1);
data[i][j]=data[i][y-1];
data[i][y-1]=0;
}
}
}
void run()
{
ans=INF;
dfs(0);
}
void ini()
{
int p,i,j;
char c;
cin>>u;
for (p=1;p<=u;p++)
{
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
cin>>c;
data[i][j]=c-'0';
}
run();
cout<<"level "<<p<<':'<<endl;
cout<<ans;
if (p!=u)
cout<<endl;
}
}
int main()
{
freopen("klgame.in","r",stdin);
freopen("klgame.out","w",stdout);
ini();
return 0;
}