• [恢]hdu 2102


    2011-12-31 18:20:59

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2102

    题意:中文。。。

    mark:你大爷的WA+TLE一共11次才AC。做了至少8个小时。

    一开始以为是要在严格的T时刻到达才可以,考虑了不可回头和可回头两种情况,dfs之,TLE。。。

    然后加奇偶剪,还是TLE。之后搜了搜,发现时T时刻以内到都可以,然后拍了个BFS。WA。

    WA了n次以后才发现时空传送是一定要传送的,不是自己选可以传也可以不传的。然后还WA,想是不是真的要在T时刻才能过,然后加了奇偶剪枝(因为回头路的话可以无限延长时间),还WA。

    最后发现一个trick是上下两层同时为#的时候不走。。。终于AC了。

    代码:

    # include <stdio.h>
    # include <string.h>


    char graph[5][15][15] ;
    int visited[5][15][15] ;
    int q[2010][3] ;
    int n, m ;
    int sx, sy, sz, ex, ey, ez ;


    void bfs ()
    {
    int front = 0, rear = 0 ;
    int i, x, y, z ;
    int xx, yy, zz ;
    int tab[4][2] = {0, 1, 0, -1, 1, 0, -1, 0} ;
    visited[sx][sy][sz] = 0 ;
    q[rear][0] = sx, q[rear][1] = sy, q[rear][2] = sz ;
    rear ++ ;
    while (front != rear)
    {
    x = q[front][0], y = q[front][1], z = q[front][2] ;
    if (x == ex && y == ey && z == ez) return ;
    front ++ ;

    for (i = 0 ; i < 4 ; i++)
    {
    xx = x ;
    yy = y + tab[i][0] ;
    zz = z + tab[i][1] ;
    if (yy < 0 || yy >= n || zz < 0 || zz >= m)
    continue ;
    if (graph[xx][yy][zz] == '#')
    {
    visited[xx][yy][zz] = -2 ;
    xx = !xx ;
    }
    if (graph[xx][yy][zz] == '#') continue ;
    if (visited[xx][yy][zz] != -1) continue ;
    if (graph[xx][yy][zz] == '*') continue ;

    visited[xx][yy][zz] = visited[x][y][z] + 1 ;
    q[rear][0] = xx, q[rear][1] = yy, q[rear][2] = zz ;
    rear++ ;
    }
    }
    }


    int main ()
    {
    int c, t, i, j, k ;
    scanf ("%d%*c", &c) ;
    while (c--)
    {
    scanf ("%d %d %d%*c", &n, &m, &t) ;
    for (j = 0 ; j < n ; j++)
    scanf ("%s%*c", graph[0][j]) ;
    scanf ("%*c") ;
    for (j = 0 ; j < n ; j++)
    scanf ("%s%*c", graph[1][j]) ;
    for (i = 0 ; i < 2 ; i++)
    for (j = 0 ; j < n ; j++)
    for (k = 0 ; k < m ; k++)
    {
    if (graph[i][j][k] == 'S')
    sx = i, sy = j, sz = k ;
    if (graph[i][j][k] == 'P')
    ex = i, ey = j, ez = k ;
    }
    memset (visited, -1, sizeof(visited)) ;
    bfs() ;
    if (visited[ex][ey][ez] == -1 ||
    visited[ex][ey][ez] > t) puts ("NO") ;
    else puts ("YES") ;
    }
    return 0 ;
    }



  • 相关阅读:
    eclipse连接远程hadoop集群开发时0700问题解决方案
    螺旋线
    双曲抛物面
    双曲抛物面
    工业相机标定相关知识整理
    高科技 stuff
    高科技 stuff
    杜甫诗百首
    杜甫诗百首
    经典纪录片
  • 原文地址:https://www.cnblogs.com/lzsz1212/p/2315431.html
Copyright © 2020-2023  润新知