设为首页 加入收藏

TOP

Codeforces 225D Snake 位运算(五)
2012-11-03 14:40:36 来源: 作者: 【 】 浏览:1347
Tags:Codeforces  225D  Snake  运算

 

    int bfs()

    {

    while(!Q.empty()) Q.pop();

    int key = hash();

    vis[st[0][0]][st [0]][key] = true;

    dis[st[0][0]][st [0]][key] = 0;

    ddd cur,tmp;

    tmp.x = st[0][0];

    tmp.y = st [0];

    tmp.s = key;

    Q.push(tmp);

    while(!Q.empty())

    {

    cur = Q.front();

    Q.pop();

    if(cur.x == edx && cur.y == edy)

    {

    return dis[edx][edy][cur.s];

    }

    for(int i=0;i<4;i++)

    {

    int tx = cur.x + move[i][0];

    int ty = cur.y + move[i] ;

    if(judge(tx , ty , cur.x , cur.y , cur.s))

    {

    tmp.x = tx;

    tmp.y = ty;

    tmp.s = hash();

    if(vis[tx][ty][tmp.s] == false)

    {

    vis[tx][ty][tmp.s] = true;

    dis[tx][ty][tmp.s] = dis[cur.x][cur.y][cur.s] + 1;

    Q.push(tmp);

    }

    }

    }

    }

    return -1;

    }

    int main()

    {

    while(~scanf("%d %d",&m,&n))

    {

    read();

    printf("%d\n",bfs());

    }

    return 0;

    }

      

首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 3261 可重叠K次的.. 下一篇c++文件处理

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: