简答题 偏难
#7131

流感传染 有一批易感人群住在网格状的宿舍区内,宿舍区为n*n的矩阵,每个格点为一个房间,房间里可能住人,也可能空着。在第一天,有些房间里的人得了流感,以后每天,…

流感传染

有一批易感人群住在网格状的宿舍区内,宿舍区为n*n的矩阵,每个格点为一个房间,房间里可能住人,也可能空着。在第一天,有些房间里的人得了流感,以后每天,得流感的人会使其邻居传染上流感,(已经得病的不变),空房间不会传染。请输出第m天得流感的人数。

时间限制:1000

内存限制:65536

输入

第一行一个数字n,n不超过100,表示有n*n的宿舍房间。 接下来的n行,每行n个字符,’.’表示第一天该房间住着健康的人,’#’表示该房间空着,’@’表示第一天该房间住着得流感的人。 接下来的一行是一个整数m,m不超过100.

输出

输出第m天,得流感的人数

样例输入

5
....#
.#.@.
.#@..
#....
.....
4

样例输出

16
未登录也能判分,登录后才会记录
答案与解析
正确答案:<pre class="brush:cpp;toolbar:false">#include &lt;cstring&gt; #include &lt;iostream&gt; using namespace std; char a[101][101], b[101][101]; int main() {   int n, m, ans = 0;   cin &gt;&gt; n;   for (int i = 1; i &lt;= n; i++)     for (int j = 1; j &lt;= n; j++)       cin &gt;&gt; a[i][j];   cin &gt;&gt; m;   for (int k = 2; k &lt;= m; k++) {     for (int i = 1; i &lt;= n; i++)       for (int j = 1; j &lt;= n; j++)         b[i][j] = a[i][j];     for (int i = 1; i &lt;= n; i++)       for (int j = 1; j &lt;= n; j++)         if (a[i][j] == '.' &amp;&amp; (b[i - 1][j] == '@' || b[i + 1][j] == '@' ||                                b[i][j - 1] == '@' || b[i][j + 1] == '@'))           a[i][j] = '@';   }   for (int i = 1; i &lt;= n; i++)     for (int j = 1; j &lt;= n; j++)       if (a[i][j] == '@')         ans++;   cout &lt;&lt; ans &lt;&lt; endl;   return 0; }</pre>
这道题暂未补解析。