zoukankan      html  css  js  c++  java
  • JZOJ.2117. 【2016-12-30普及组模拟】台风

    题目大意:

      天气预报频道每天从卫星上接受卫星云图。图片被看作是一个矩阵,每个位置上要么是”#”,要么”.”,”#”表示该位置没有云,”.”表示有云,地图上每个位置有多达8个相邻位置,分别是,左上、上、右上、左、右、左下、下、右下8个方向,一块云是由连续的”.”组成。
    例如:下面的卫星云图有4块云:

    #####.#####

    ####.####.#

    ###..##.#.#

    ##...######

    ######.....

    ###########

    如果当云的大小大于等于4的时候会产生台风,那么上图有将会产生2个台风,分别用1和2表示:

    #####1#####

    ####1####.#

    ###11##.#.#

    ##111######

    ######22222

    ###########

    给你一幅卫星云图和形成台风所需云的大小,要你计算出有几个台风以及最大台风的大小。我们用云的大小表示台风的大小。

    一波解析:

      

    从上到小从左到右扫描卫星云图,如果某位置(a[i,j]=’.’)and(f[i,j]=false),则从(i,j)出发进行FllodFill,把所有和它相连的位置全部更新为True,同时记录数量num,其他操作比较简单,就不用说了。

    ALL IN ALL 就是一句话:白~~~~~番~~~~~薯(bfs)

    code

      

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 int n,m;
     7 char map[1001][1001];
     8 int cnt;
     9 int ans;
    10 int maxn=-1;
    11 int k;
    12 int hx[10000010];
    13 int hxx[1000010];
    14 int dx[8]= {1,0,-1,0,1,-1,1,-1};
    15 int dy[8]= {0,1,0,-1,1,1,-1,-1};
    16 void bfs(int x,int y) {//白番薯 
    17     int head=0;
    18     int tail=1;
    19     hx[tail]=x;
    20     hxx[tail]=y;
    21     do 
    22     {
    23         head++;
    24         for(int i=0; i<8; i++) 
    25         {
    26             int nx=hx[head]+dx[i];
    27             int ny=hxx[head]+dy[i];
    28             if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&map[nx][ny]=='.') 
    29             {
    30                 tail++;
    31                 hx[tail]=nx;
    32                 hxx[tail]=ny;
    33                 map[nx][ny]='#';
    34                 cnt++;
    35             }
    36         }
    37     } while(head<tail);
    38 }
    39 int main() 
    40 {
    41     freopen("storm.in","r",stdin);
    42     freopen("storm.out","w",stdout);
    43     cin>>n>>m;
    44     for(int i=1; i<=n; i++)
    45     {
    46         for(int j=1; j<=m; j++)
    47         {
    48             cin>>map[i][j];
    49         }
    50     }
    51     cin>>k;
    52     for(int i=1; i<=n; i++) 
    53     {
    54         for(int j=1; j<=m; j++) 
    55         {
    56             if(map[i][j]=='.') 
    57             {
    58                 cnt=0;
    59                 bfs(i,j);
    60                 if(cnt>=k) 
    61                 {
    62                     ans++;
    63                     maxn=max(maxn,cnt);
    64                 }
    65             }
    66         }
    67     }
    68     cout<<ans<<" "<<maxn;
    69     return 0;
    70 }//bird bird 牛逼!!
  • 相关阅读:
    ctf web 百度杯”CTF比赛 九月场Upload i春秋
    ctf web 西普实验吧 登陆一下好吗 MySQL隐式转化 MySQL表达式的计算顺序
    Firefox 47.0.1
    给数组原型添加方法
    JS中几种常见的数组算法(前端面试必看)
    进制转换技巧解析
    redis通过6379端口无法连接服务器
    阿里云图片或文件上传 启动时报Error creating bean with name 'ossClient'问题
    20170628-三七互娱-测试工程师(提前批)
    20170514-vivo-软件工程师Java(提前批)
  • 原文地址:https://www.cnblogs.com/WestJackson/p/11388579.html
Copyright © 2011-2022 走看看