| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么WA~~~自己测试都是对的#include <iostream>
#include <queue>
using namespace std;
bool bfs();
int change[4][4] =
{
0xf888,0xf444,0xf222,0xf111,
0x8f88,0x4f44,0x2f22,0x1f11,
0x88f8,0x44f4,0x22f2,0x11f1,
0x888f,0x444f,0x222f,0x111f
};
struct Node
{
int x,y;
int last;
int step;
};
int start,temp;
Node state[70000];
bool used[70000];
int flag;
void finds(int n)
{
if (state[n].last == -1)
return;
finds(state[n].last);
printf("%d %d\n",state[n].x+1,state[n].y+1);
return;
}
int main()
{
int i,j,k,m,n,t;
char str[4][4];
start = 0;
// while (scanf("%s",str[0])!=EOF)
// {
k=15;
// for (i=0;i<4;i++)
// {
// if (str[0][i] == '+') //如果为关,为1
// {
// start |= (1<<k);
// }
// k--;
// }
for (i=0;i<4;i++)
{
scanf("%s",str[i]);
}
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
{
if (str[i][j] == '+')
{
start |= (1<<k);
}
k--;
}
}
//-------------------------------------------------------
memset(used,0,sizeof(used));
flag = 0;
bfs();
// if()
// {
printf("%d\n",state[0].step);
finds(0);
// }
// else
// printf("0\n");
// }
return 0;
}
bool bfs()
{
int i,j,t;
int head = 0;
int tail = 1;
queue <int> Q;
Q.push(start);
used[start] = 1;
state[start].last = -1;
state[start].step = 0;
while (!Q.empty() && t!=0)
{
temp = Q.front();
Q.pop();
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
{
t = temp^change[i][j];
if (!used[t])
{
Q.push(t);
state[t].last = temp;
state[t].step = state[temp].step + 1;
state[t].x = i;
state[t].y = j;
used[t] = 1; //标记已用
if (t == 0) //如果找到就退出
{
break;
}
}
}
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator