• uva 784 Maze Exploration


    题意:填满能走的空间

    解题思路:(大水题)深搜

    解题代码:

    // File Name: uva784.c
    // Author: darkdream
    // Created Time: 2013年05月22日 星期三 21时15分59秒
    
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    char str[100][100];
    int visit[100][100];
    struct node
    {
      int x, y ;
    }nodes[1000];
    int xadd[] = {+1,-1,0,0};
    int yadd[] = {0,0,+1,-1};
    int main(){
    
       //freopen("/home/plac/problem/input.txt","r",stdin);
       //freopen("/home/plac/problem/output.txt","w",stdout);
       int n ;
       scanf("%d",&n);
       getchar();
       while(n--)
       {
           memset(str,0,sizeof(str));
           memset(visit,0,sizeof(visit));
           int m ;
           for(int i =1 ; ;i ++)
           {
              gets(&str[i][1]);
              if(str[i][1] == '_')
              {
                m = i-1;
                break;
              }
           }
           int fx,fy;
           for(int i = 1; i <= m;i ++)
           {
              for(int j = 1; j <= 80 ;j ++)
              {
                if(str[i][j] == '*')
                {  
                    fx = i ;
                    fy = j;
                    break;
                }
              }
           }
           int low = 1, high = 1;
           nodes[1].x = fx;
           nodes[1].y = fy;
           str[fx][fy] = '#';
           while(low <= high)
           {
              for(int tp = 0 ; tp < 4; tp++)
              {
                 int tx = nodes[low].x + xadd[tp];
                 int ty = nodes[low].y + yadd[tp];
                 if(str[tx][ty] == ' ')
                 {
                     str[tx][ty] = '#';
                     high++;
                     nodes[high].x = tx;
                     nodes[high].y = ty;
                 }
                 
              }
              low++;
             
           }
           for(int i =1 ;i <= m+1;i ++)
           {
              puts(&str[i][1]);
           }
    
    
       }
    return 0 ;
    }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    JavaScript访问ab页面定时跳转代码
    http协议相关-待续
    curl发送get和post请求
    Java入门——动态网页jsp(jdk下载和配置环境变量)
    LeetCode:Best Time to Buy and Sell Stock
    LeetCode:Reverse Integer
    LeetCode:Same Tree
    LeetCode:Single Number II
    LeetCode:Single Number
    LeetCode:Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/zyue/p/3093746.html
Copyright © 2020-2023  润新知