• hdu--2579--第二次与女孩的约会


    我去....这题 真无语了

    忘记清空队列了....当然 你要是将队列声明在函数中 就没这个烦恼了 每次调用相当于清空了

    而我 是将它声明为全局变量的...

    卧槽了 坑死了

    这题 抛开这个不讲

    女孩子还是很有心思的...

    要用三维vis数组 第三位表示的状态是移动到那一步%k所余的时间  因为题目条件的特殊性 石头在time%k==0的时候会消失 所以需要这样设、

    除了这一点之外 其它没什么了  是个很普通的bfs 从一层状态搜索到下一层的状态

     1 #include <iostream>
     2 #include <cstring>
     3 #include <queue>
     4 using namespace std;
     5 
     6 const int size = 110;
     7 int stx , sty;
     8 int n , m , k;
     9 int dir[4][2] = {1,0,-1,0,0,1,0,-1};
    10 char mp[size][size];
    11 bool vis[size][size][15];
    12 struct node
    13 {
    14     int x;
    15     int y;
    16     int step;
    17     node( int a , int b , int c ):x(a),y(b),step(c){};
    18     node(){};
    19 };
    20 queue<node>q;
    21 
    22 int bfs( )
    23 {
    24     while(!q.empty())
    25         q.pop();
    26     int ans = -1;
    27     int xx , yy , step;
    28     node now;
    29     q.push( node(stx,sty,0) );
    30     vis[stx][sty][0] = true;
    31     while( !q.empty() )
    32     {
    33         now = q.front();
    34         q.pop();
    35         if( mp[now.x][now.y] == 'G' )
    36             return now.step;
    37         for( int i = 0 ; i<4 ; i++ )
    38         {
    39             xx = now.x + dir[i][0];
    40             yy = now.y + dir[i][1];
    41             step = (now.step+1)%k;
    42             if( xx>=1 && xx<=n && yy>=1 && yy<=m && !vis[xx][yy][step] )
    43             {
    44                 if( mp[xx][yy] == '#' && !step )
    45                 {
    46                     q.push( node(xx,yy,now.step+1) );
    47                     vis[xx][yy][step] = true;
    48                 }
    49                 if( mp[xx][yy]!='#' )
    50                 {
    51                     q.push( node(xx,yy,now.step+1) );
    52                     vis[xx][yy][step] = true;
    53                 }
    54             }
    55         }
    56     }
    57     return ans;
    58 }
    59 
    60 int main()
    61 {
    62     cin.sync_with_stdio(false);
    63     int t , ans;
    64     cin >> t;
    65     while(t--)
    66     {
    67         cin >> n >> m >> k;
    68         memset( vis , false , sizeof(vis) );
    69         for( int i = 1 ; i<=n ; i++ )
    70         {
    71             for( int j = 1 ; j<=m ; j++ )
    72             {
    73                 cin >> mp[i][j];
    74                 if( mp[i][j] == 'Y' )
    75                 {
    76                     stx = i;
    77                     sty = j;
    78                 }
    79             }
    80         }
    81         ans = bfs( );
    82         if( ans == -1 )
    83             cout << "Please give me another chance!" << endl;
    84         else
    85             cout << ans << endl;
    86     }
    87     return 0;
    88 }
    View Code

    today:

      某天

      你无端想起一个人

      她曾让你对明天有所期望

      但是却完全没有出现在你的明天里

    just follow your heart
  • 相关阅读:
    servlet学习之servletAPI编程常用的接口和类
    问题解决
    HTTP Status 500 – Internal Server Error
    用数组模拟队列
    稀疏数组
    值传递机制及几道网红题目
    关于Tomcat配置问题
    Servlet学习笔记
    面向对象笔记
    数组中涉及的常见算法
  • 原文地址:https://www.cnblogs.com/radical/p/3951515.html
Copyright © 2020-2023  润新知