Asteroids! hdu 1240 终于AC
来源:互联网 发布:fanuc plc编程软件 编辑:程序博客网 时间:2024/06/05 19:18
/*
很水的bfs,一开始bfs不会,用dfs错了好多次,应该是算法有问题吧,我觉得这个题目用dfs
应该可以的
*/
#include<iostream>//2389356 2010-04-27 11:23:31 Accepted 1240 0MS 308K 1495 B C++ 悔惜晟
#include<queue>
#include<cstring>
#include<cmath>
using namespace std;
char map[12][12][12];
bool hash[12][12][12];
bool flag;
int dir[6][3] = {{0, 0, 1}, {0, 1, 0}, {0, 0, -1}, {0, -1, 0}, {1, 0, 0}, {-1, 0, 0} };
int a, b, c;
int d, e, f;
int t;
int n;
struct node
{
int x;
int y;
int z;
int num;
};
queue<node> q;
int bfs(int si, int sj, int sk)
{
node N, P;
N.x = si;
N.y = sj;
N.z = sk;
N.num = 0;
int i;
q.push(N);
hash[si][sj][sk] = false;
while(!q.empty())
{
N = q.front();
if(N.x == f && N.y == e && N.z == d && N.num == t)
{
flag = true;
cout<<n<<" "<<N.num<<endl;
break;
}
if(N.num > t)
{
break;
}
q.pop();
for(i = 0; i < 6; i++)
{
P.x = N.x + dir[i][0];
P.y = N.y + dir[i][1];
P.z = N.z + dir[i][2];
if(P.x >= 0 && P.x < n && P.y >= 0 && P.y < n && P.z >= 0 && P.z < n && hash[P.x][P.y][P.z] && map[P.x][P.y][P.z] == 'O')
{
P.num = N.num + 1;
q.push(P);
hash[P.x][P.y][P.z] = false;
}
}
}
return 1;
}
int main()
{
char str[12];
int i, j ,k;
while(cin>>str>>n)
{
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
for(k = 0; k < n; k++)
cin>>map[i][j][k];
cin>>a>>b>>c;
cin>>d>>e>>f;
cin>>str;
t = (int)(fabs(1.0*a - d) + fabs(1.0*b - e) + fabs(1.0*c - f)); //省赛的时候这样的CE过
flag = false;
memset(hash, true, sizeof(hash));//一开始这里标记错了,以后应该规定标记的,不然写写就会错了
bfs(c, b ,a);
if(!flag)
cout<<"NO ROUTE"<<endl;
}
}
- Asteroids! hdu 1240 终于AC
- hdu 1240 Asteroids!
- HDU-1240-Asteroids!
- hdu 1240 Asteroids!
- hdu 1240 Asteroids!
- Hdu 1240 Asteroids!
- hdu 1240 Asteroids!
- hdu 1240 Asteroids!
- HDU 1240 Asteroids!
- hdu 1240 Asteroids BFS
- HDU 1240 Asteroids!
- hdu 1240 Asteroids!
- hdu-1240-Asteroids!
- HDU 1240 Asteroids!
- hdu 1240 Asteroids!bfs
- Asteroids! HDU 1240
- HDU 1240 Asteroids!(BFS)
- hdu 1240 Asteroids!(BFS)
- 截断数据库日志
- Struts2 设置session及获取spring aplicationicontext
- php面试题附答案
- 用SuperMap输出GoogleMap地图
- 2010年4月27日(新公司入职,第四周星期二)
- Asteroids! hdu 1240 终于AC
- 线段树的简单应用;火车订票;线段树用起来太灵活了!;
- 网页播放视频解决代码(来自百度知道)
- gamebryo的Badsushi例子学习
- Myeclipse+Ajax 例子
- datagridview实现列锁定
- 通过设置myeclipse配置信息来优化性能
- 如何:运行远程调试监视器
- 字节序问题--大端法小端法