zoukankan      html  css  js  c++  java
  • Problem H: 小火山的围棋梦想 多校训练2(小火山专场)

    题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1908

    题意:如果'.'被'*'围起来,就把'.'变为'*'。

    分析:如果是'*'直接输出,如果是'.' 则要对其搜索

    如果四个方向都是封闭的,则可以改变。即w[i][j]=4;

    如果查询的是'*'或者查询的是已被查询过的'.'  ,则记录上;

    如果查询的是'.'而且没有查询标记过,则进行查询;

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<queue>
     6 #include<stdlib.h>
     7 #include<map>
     8 #include<cmath>
     9 
    10 using namespace std;
    11 
    12 #define N 50
    13 #define INF 0x3f3f3f3f
    14 
    15 char s[N][N];
    16 int w[N][N],b[N][N],n,m;
    17 int dir[4][2]= { {1,0},{0,1},{-1,0},{0,-1} };
    18 
    19 int q(int x,int y)
    20 {
    21     int i;
    22 
    23     b[x][y]=1;
    24     for(i=0; i<4; i++)
    25     {
    26         int xx=x+dir[i][0];
    27         int yy=y+dir[i][1];
    28         if(xx>=0&&xx<n&&yy>=0&&yy<m&&(s[xx][yy]=='*'||b[xx][yy]))
    29             w[x][y]++;
    30         if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]=='.'&&!b[xx][yy])
    31         {
    32             if(q(xx,yy)==1)
    33                 w[x][y]++;
    34         }
    35     }
    36 
    37     if(w[x][y]==4)
    38         return 1;
    39     return 0;
    40 }
    41 
    42 int main()
    43 {
    44     int T,k=1,i,j;
    45 
    46     scanf("%d", &T);
    47 
    48     while(T--)
    49     {
    50         memset(w,0,sizeof(w));
    51 
    52         scanf("%d %d", &n,&m);
    53 
    54         for(i=0; i<n; i++)
    55             scanf("%s", s[i]);
    56 
    57         printf("Case %d:
    ",k++);
    58 
    59         for(i=0; i<n; i++)
    60         {
    61             for(j=0; j<m; j++)
    62             {
    63                 if(s[i][j]=='.')
    64                 {
    65                     memset(w,0,sizeof(w));
    66                     memset(b,0,sizeof(b));
    67 
    68                     if(q(i,j)==1)
    69                         s[i][j]='*';
    70                 }
    71 
    72                 printf("%c", s[i][j]);
    73             }
    74             printf("
    ");
    75         }
    76     }
    77     return 0;
    78 }
  • 相关阅读:
    Win7远程连接凭据不工作的诡异问题解决
    pip介绍与使用
    Java Web整合开发(35) -- JPA规范
    爬虫
    零基础自学用Python 3开发网络爬虫
    learn资料
    Linux定时任务Crontab命令详解 转
    VirtualBox Host-only Adapter,Failed to create the host-only adapter 转
    Nginx报 No input file specified. 的问题解决之路 转
    ci上传图片
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5757895.html
Copyright © 2011-2022 走看看