主题列表页 发帖图标旁 加 【本版搜索】代码
[attach]1354[/attach]打开:forumdisplay.htm
找到:[code]{lang send_posts}</a></span>[/code]
下面添加:**** Hidden Message ***** 谢谢分享 超喜欢你这个的论坛 支持LZ分享免费东西 支持LZ分享免费东西 谢谢分享
本文摘自:oocn资源论坛([url]http://oocn.258club.com[/url]) 详细出处请参考:[url]http://oocn.258club.com/thread-3616-1-1.html[/url] 很实用的效果 谢谢分享 [quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/14120408334dbd1f1f6e6bfb6b.png[/img][/quote] :L 这都要隐藏啊…… [quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/141204083334b4c301ee1ebc32.png[/img][/quote] [quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/1412040833c3cc872579ec9bec.png[/img][/quote] [quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/14120408338267b09a2bad1fe1.png[/img][/quote] [quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/14120408338267b09a2bad1fe1.png[/img][/quote] 感谢楼主分享 [quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/1412040833c3cc872579ec9bec.png[/img][/quote] [quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/1412040833f4a3160f9cd1db35.png[/img][/quote] 支持您的分享 支持您的分享 [b]回复 [url=http://www.oocn.258club.com/redirect.php?goto=findpost&pid=16367&ptid=3607]1#[/url] [i]oocn[/i] [/b]
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int T,ans=20,flag;
int xx[9]={0,-2,-2,-1,-1,1,1,2,2};
int yy[9]={0,-1,1,-2,2,2,-2,1,-1};
int s[10][7],get[10][10];
int map[10][10];
char si;
int Judge()
{
int ret=0;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
if(s[i][j]!=map[i][j])
{
ret++;
}
}
}
return ret;
}
void dfs(int now,int x,int y,int sum)
{
if(flag!=0)
{
return;
}
int c=Judge();
if(now==sum)
{
if(c==0)
{
flag=1;
ans=sum;
}
}
if(now-1+c>sum)
{
return;
}
for(int i=1;i<=8;i++)
{
int nx=x+xx[i];
int ny=y+yy[i];
if(nx>0 && nx<=5 && ny>0 && ny<=5)
{
swap(s[x][y],s[nx][ny]);
dfs(now+1,nx,ny,sum);
swap(s[x][y],s[nx][ny]);
}
}
}
int main()
{
scanf("%d",&T);
map[1][1]=1;
map[1][2]=1;
map[1][3]=1;
map[1][4]=1;
map[1][5]=1;
map[2][1]=0;
map[2][2]=1;
map[2][3]=1;
map[2][4]=1;
map[2][5]=1;
map[3][1]=0;
map[3][2]=0;
map[3][3]=2;
map[3][4]=1;
map[3][5]=1;
map[4][1]=0;
map[4][2]=0;
map[4][3]=0;
map[4][4]=0;
map[4][5]=1;
map[5][1]=0;
map[5][2]=0;
map[5][3]=0;
map[5][4]=0;
map[5][5]=0;
while(T--)
{
int x,y;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
cin>>si;
if(si=='*')
{
x=i;
y=j;
get[i][j]=2;
}
else
{
get[i][j]=si-'0';
}
}
}
for(int k=0;k<=20;k++)
{
flag=0;
ans=20;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
s[i][j]=get[i][j];
}
}
dfs(0,x,y,k);
if(ans==k)
{
break;
}
}
if(ans<=15)
{
printf("%d\n",ans);
}
else
{
printf("-1\n");
}
}
return 0;
} 支持您的分享
页:
[1]
2