Problem H: 小火山的圍棋夢想 多校訓練2(小火山專場)

來源:互聯網
上載者:User

標籤:

題目連結: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 5013 #define INF 0x3f3f3f3f14 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:\n",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("\n");75         }76     }77     return 0;78 }

 

Problem H: 小火山的圍棋夢想 多校訓練2(小火山專場)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.