首页 > 其他 > 详细

CF1059B Forgery

时间:2018-10-06 21:15:14      阅读:145      评论:0      收藏:0      [点我收藏+]

思路:

若某个位置是‘.’,说明不能在周围的8个位置下笔。在所有可以下笔的位置填充一次,看能否“包含”需要的图案即可。

实现:

 1 #include <iostream>
 2 using namespace std;
 3 const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
 4 const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 5 char a[1005][1005], b[1005][1005];
 6 int ok[1005][1005];
 7 int main()
 8 {
 9     int n, m;
10     while (cin >> n >> m)
11     {
12         for (int i = 0; i < n; i++)
13         {
14             for (int j = 0; j < m; j++)
15             {
16                 cin >> a[i][j];
17                 if (i == 0 || i == n - 1 || j == 0 || j == m - 1)
18                     ok[i][j] = 0;
19                 else ok[i][j] = 1;
20             }
21         }
22         for (int i = 1; i < n - 1; i++)
23         {
24             for (int j = 1; j < m - 1; j++)
25             {
26                 if (a[i][j] == .)
27                 {
28                     for (int k = 0; k < 8; k++)
29                     {
30                         int nx = i + dx[k], ny = j + dy[k];
31                         ok[nx][ny] = 0;
32                     }
33                 }
34             }
35         }
36         for (int i = 0; i < n; i++)
37         {
38             for (int j = 0; j < m; j++)
39             {
40                 if (ok[i][j])
41                 {
42                     for (int k = 0; k < 8; k++)
43                     {
44                         int nx = i + dx[k], ny = j + dy[k];
45                         b[nx][ny] = #;
46                     }
47                 }
48             }
49         }
50         bool flg = true;
51         for (int i = 0; i < n; i++)
52         {
53             for (int j = 0; j < m; j++)
54             {
55                 if (a[i][j] == # && b[i][j] != #)
56                 {
57                     flg = false; break;
58                 }
59             }
60         }
61         cout << (flg ? "yes" : "no") << endl;
62     }
63     return 0;
64 }

 

CF1059B Forgery

原文:https://www.cnblogs.com/wangyiming/p/9748328.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!