1个回答
2013-11-16
展开全部
#include <cstdlib>
#include <iostream>
using namespace std;
int s[15][15];
int x, y;
int a[15][15];
int s1, s2;
int e1, e2;
int i, j, k;
int m;
void dfs(int x, int y, int m)
{
if (m > a[x][y]) return;
s[x][y] = 10;
a[x][y] = m;
if (s[x][y] == 5)
return;
dfs(x + 2, y + 1, m++);
dfs(x + 2, y - 1, m++);
dfs(x - 2, y + 1, m++);
dfs(x - 2, y - 1, m++);
dfs(x + 1, y + 2, m++);
dfs(x + 1, y - 2, m++);
dfs(x - 1, y + 2, m++);
dfs(x - 1, y - 2, m++);
return;
}
int main(int argc, char *argv[])
{
cin >> s1 >> s2;
cin >> e1 >> e2;
s1++;
s2++;
e2++;
e1++;
for (i = 0; i <= 15; i++)
for (j = 0; j <= 15; j++)
{
s[i][j] = 10;
a[i][j] = 100;
}
for (i = 2; i <= 12; i++)
for (j = 2; j <= 10; j++)
s[i][j] = 0;
/*
for (i = 0; i <= 15; i++)
{
for (j = 0; j <= 15; j++)
cout << s[i][j] << " ";
cout << endl;
}
*/
s[e1][e2] = 5;
dfs(s1, s2, 1);
cout << a[e1][e2] << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
int s[15][15];
int x, y;
int a[15][15];
int s1, s2;
int e1, e2;
int i, j, k;
int m;
void dfs(int x, int y, int m)
{
if (m > a[x][y]) return;
s[x][y] = 10;
a[x][y] = m;
if (s[x][y] == 5)
return;
dfs(x + 2, y + 1, m++);
dfs(x + 2, y - 1, m++);
dfs(x - 2, y + 1, m++);
dfs(x - 2, y - 1, m++);
dfs(x + 1, y + 2, m++);
dfs(x + 1, y - 2, m++);
dfs(x - 1, y + 2, m++);
dfs(x - 1, y - 2, m++);
return;
}
int main(int argc, char *argv[])
{
cin >> s1 >> s2;
cin >> e1 >> e2;
s1++;
s2++;
e2++;
e1++;
for (i = 0; i <= 15; i++)
for (j = 0; j <= 15; j++)
{
s[i][j] = 10;
a[i][j] = 100;
}
for (i = 2; i <= 12; i++)
for (j = 2; j <= 10; j++)
s[i][j] = 0;
/*
for (i = 0; i <= 15; i++)
{
for (j = 0; j <= 15; j++)
cout << s[i][j] << " ";
cout << endl;
}
*/
s[e1][e2] = 5;
dfs(s1, s2, 1);
cout << a[e1][e2] << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询