在一张白色背景的图像上,有一些色的字符。小度发现这些字符可以分成三类:不含任何洞的字符”1”,含个洞
的字符"0”,含两个洞的字符“8”。现在, 用"示色背景,用"#" 示背景上的艷字迹,小度想问问你,
这三类字符各有多少个?
保证字符之间互不嵌套或重叠,字符的各个洞的位置不重叠,字符的每个"#"之间四联通。
格式
输入格式:第一行两个整数n(1 ≤n≤1000)和m(1≤n≤1000)。
随后n行,每行m个字符,示该该白图像。
输出格式:输出一行三个整数,分别表示”1” 的个数、"0” 的个数和"8” 的个数。
样例1
输入: 3 11
#.###. #####
#.#.#.#.#.#
#. ### . #####
输出:111
AC代码:
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
-
- #define ll long long
- #define PII pair
- const int N=1010;
-
- int n,m;
- int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
- char mp[N][N];
- bool st[N][N];
- queue
q; - int r1,r0,r8;
-
- void bfs(int sx,int sy)
- {
- int cnt=0;
- q.push({sx,sy});
- st[sx][sy]=1;
- while(q.size())
- {
- cnt++;
- PII t=q.front();
- q.pop();
-
- for(int i=0;i<4;i++)
- {
- int xx=t.first+dx[i],yy=t.second+dy[i];
- if(xx<0||xx>n-1||yy<0||yy>m-1)
- continue;
- if(st[xx][yy]||mp[xx][yy]=='.')
- continue;
- q.push({xx,yy});
- st[xx][yy]=1;
- }
- }
-
- r8+=cnt/13;
- cnt%=13;
- r0+=cnt/8;
- cnt%=8;
- r1+=cnt/3;
-
- }
-
- int main()
- {
- scanf("%d%d",&n,&m);
- for(int i=0;i
- scanf("%s",mp[i]);
-
- int res=0;
- for(int i=0;i
- for(int j=0;j
- if(!st[i][j]&&mp[i][j]=='#')
- bfs(i,j);
- printf("%d %d %d\n",r1,r0,r8);
- }
-
相关阅读:
21.Python函数(六)【函数式编程 下半篇】
svg 简单的动画
勒索病毒最新变种.faust勒索病毒来袭,如何恢复受感染的数据?
A、B、C三类地址中私有地址的范围?
DevNet: Deviation Aware Networkfor Lane Detection
程序员转正述职报告/总结
C#数据类型
C# 轻量级 ORM 框架 NPoco 的简单应用
subline text3安装numpy,scipy,matplotlib,pandas,sklearn,ipynb
每日一题~合并二叉树
-
原文地址:https://blog.csdn.net/qq_62242287/article/details/126693149