NBUT 1122 Shameimaru's Candid Camera(水)

题意:给n*m个格子,初始时每个格子中有个数值为0,部分格子中含有炸弹,每个炸弹爆炸可以将周围的8个非炸弹格子中的数值加1,求全部炸弹炸完后那些非0且非炸弹格子中的数是多少。

思路:另开一个矩阵,每炸弹一炸就9个格子全加1,全炸完后再输出时判断是否为0,若是则输出‘-‘,否则,若是炸弹格子则输出‘*‘,若是数字就输出该数字。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int a[550][550];//统计数值
 4 int n, m;
 5 bool b[550][550];
 6 void cal(int x,int y)//9个全加,没关系
 7 {
 8     a[x-1][y-1]++;
 9     a[x-1][y]++;
10     a[x-1][y+1]++;
11
12     a[x+1][y-1]++;
13     a[x+1][y]++;
14     a[x+1][y+1]++;
15
16     a[x][y+1]++;
17     a[x][y]++;
18     a[x][y-1]++;
19 }
20
21 int main()
22 {
23     //freopen("input.txt", "r", stdin);
24     int flag=0;
25     char c;
26     while(cin>>n>>m)
27     {
28         if(flag>0)    printf("\n");//输出格式?
29         else    flag++;
30         memset(a,0,sizeof(a));
31         memset(b,0,sizeof(b));
32
33         for(int i=1; i<=m; i++) //宽度
34             for(int j=1; j<=n; j++) //高度
35             {
36                 cin>>c;
37                 if(c==‘*‘)    b[i][j]=true; //负代表不能累加
38             }
39
40         for(int i=1; i<=m; i++)
41             for(int j=1; j<=n; j++)
42                 if(b[i][j]==true)    cal(i,j);
43
44         for(int i=1; i<=m; i++)
45         {
46             for(int j=1; j<=n; j++)
47             {
48                 if(b[i][j]==false)
49                 {
50                     if(a[i][j]>0)
51                         printf("%d",a[i][j]);
52                     else
53                         printf("-");
54                 }
55                 else
56                     printf("*");
57             }
58             printf("\n");
59         }
60     }
61     return 0;
62 }

AC代码

NBUT 1122 Shameimaru's Candid Camera(水)

时间: 2024-08-24 09:40:13

NBUT 1122 Shameimaru's Candid Camera(水)的相关文章

ACM: NBUT 1105 多连块拼图 - 水题 - 模拟

NBUT 1105  多连块拼图 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format: Practice Appoint description:  System Crawler  (Aug 12, 2016 9:32:14 AM) Description 多连块是指由多个等大正方形边与边连接而成的平面连通图形. -- 维基百科 给一个大多连块和小多连块,你的任务是判断大多连块是否可以由两个这样的小多连块拼成.小多连块只能

英语电影剧本大全(中英对照)

目     录 <泰坦尼克号>全部英文剧本 TV REPORTER: Treasure hunter Brock Lovett is best known for finding Spanish gold off islands in the best Caribbean. LIZZY: It’s OK, I’ll get you in a minutes. Come on. TV REPORTER: Now he is using Russian subs to reach the most

NBUT 1186 Get the Width(DFS求树的宽度,水题)

[1186] Get the Width 时间限制: 1000 ms 内存限制: 65535 K 问题描述 It's an easy problem. I will give you a binary tree. You just need to tell me the width of the binary tree. The width of a binary tree means the maximum number of nodes in a same level. For exampl

NBUT 1118 Marisa&#39;s Affair (排序统计,水)

题意:每行给出一个人名和一个int值,人名可重复出现.要求对同一个人名统计int值,最大的先输出,若相同,则按照人名出现次数,若再相同,则按照人名字典序. 思路:输入完全部进行排序,写个比较函数传进去sort即可. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 struct node 5 { 6 char nam[22]; 7 int lik; 8 int tim; 9 }a[5500]; 10 11 map<string,

NBUT 1115 Cirno&#39;s Trick (超水)

题意:给出多个double数,去掉其最小的和最大的,再对余下的求均值. 思路:再输入时将最大和最小去掉,顺便统计非最值的和,输出时除一下个数即可. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main() 5 { 6 //freopen("input.txt", "r", stdin); 7 int n; 8 while(~scanf("%d",&n))

NBUT 1114 Alice&#39;s Puppets(排序统计,水)

题意:给一棵人名树,按层输出,同层则按名字的字典序输出. 思路:首先对每个人名做索引,确定其在哪一层,按层装进一个set,再按层输出就自动排好序了. 1 #include <bits/stdc++.h> 2 using namespace std; 3 vector< set<string> > ord; //每层一个set,自动按照字典序排好了 4 map<string,int> mapp; //作哈希用 5 6 int main() 7 { 8 //fr

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

水漫填充

水漫填充:floodFill()函数 int floodFill( InputOutputArray image, InputOutputArray mask, Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0, Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), int flags = 4 ); int floodFill( InputOutputArray image, Point se

NBUT 1457 Sona (莫队算法)

题目大意: 求一段区间内 出现的数字的次数的三次方的和 思路分析: 这要水过去的题目真是难,各种优化. 不能用map , 要离散化之后 先处理lowerbound.优化输入... 时间卡的很紧.. 题目直接用莫队水过去. 如果你超时的话,不妨试试上面三种优化. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <map> #