Helvetic Coding Contest 2016 online mirror D1
Description
"The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segments. We call on you for help. Go forth and explore the wall! Report how many disconnected segments there are.
The wall is a two-dimensional structure made of bricks. Each brick is one unit wide and one unit high. Bricks are stacked on top of each other to form columns that are up to R bricks high. Each brick is placed either on the ground or directly on top of another brick. Consecutive non-empty columns form a wall segment. The entire wall, all the segments and empty columns in-between, is C columns wide.
The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:
- each of the R lines contains a string of length C,
- the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise.
The input will contain at least one character B and it will be valid.
The number of wall segments in the input configuration.
3 7
.......
.......
.BB.B..
2
4 5
..B..
..B..
B.B.B
BBB.B
2
4 6
..B...
B.B.BB
BBB.BB
BBBBBB
1
1 1
B
1
10 7
.......
.......
.......
.......
.......
.......
.......
.......
...B...
B.BB.B.
3
8 8
........
........
........
........
.B......
.B.....B
.B.....B
.BB...BB
2
In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second.
判断连通块
#include <bits/stdc++.h>
using namespace std; int n,m;
char ma[200][200];
int vis[200][200];
void dfs(int x,int y)
{
if(x<0||x>=n||y<0||y>=m)return;
if(ma[x][y]=='.')return;
if(vis[x][y])return;
vis[x][y]=1;
if(ma[x][y]=='B')ma[x][y]='.';
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x,y-1); }
int main()
{
while(~scanf("%d%d",&n,&m)){
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
scanf("%s",ma[i]);
int ans=0;
for(int i=0;i<n;i++)
for(int k=0;k<m;k++)
if(ma[i][k]=='B')
ans++,dfs(i,k);
printf("%d\n",ans);}
return 0;
}
Helvetic Coding Contest 2016 online mirror D1的更多相关文章
- CF 690C3. Brain Network (hard) from Helvetic Coding Contest 2016 online mirror (teams, unrated)
题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一 ...
- Helvetic Coding Contest 2016 online mirror A1
Description Tonight is brain dinner night and all zombies will gather together to scarf down some de ...
- Helvetic Coding Contest 2016 online mirror F1
Description Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure ...
- Helvetic Coding Contest 2016 online mirror B1
Description The zombies are gathering in their secret lair! Heidi will strike hard to destroy them o ...
- Helvetic Coding Contest 2016 online mirror C2
Description Further research on zombie thought processes yielded interesting results. As we know fro ...
- Helvetic Coding Contest 2016 online mirror C1
Description One particularly well-known fact about zombies is that they move and think terribly slow ...
- Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)
http://codeforces.com/contest/1184 A1 找一对整数,使x^x+2xy+x+1=r 变换成一个分式,保证整除 #include<iostream> #in ...
- [Helvetic Coding Contest 2017 online mirror]
来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包 ...
- 【Codeforces】Helvetic Coding Contest 2017 online mirror比赛记
第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: l ...
随机推荐
- [BALTIC 2008] Grid
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1169 [算法] 首先DFS枚举出横着切的 然后二分 + 贪心即可 时间复杂度 : O ...
- Starting MySQL....The server quit without updating PID file错误解决办法
出现错误:Starting MySQL....The server quit without updating PID file 检查错误文件: /var/lib/mysql/xxxx.err,根据其 ...
- Poj 2304 Combination Lock(模拟顺、逆时钟开组合锁)
一.题目大意 模拟一个开组合的密码锁过程.就像电影你开保险箱一样,左转几圈右转几圈的就搞定了.这个牌子的锁呢,也有它独特的转法.这个锁呢,有一个转盘,刻度为0~39.在正北方向上有一个刻度指针.它的密 ...
- 给.sh文件添加可执行权限
有时我们运行.sh文件时会发现没有权限,具体解决方案如下 第一种:bash+执行文件 第二种:chmod命令 如果给所有人添加可执行权限:chmod a+x 文件名:如果给文件所有者添加可执行权限:c ...
- js产生不同的随机数
前言:前几天写到一个程序,用到要使用不同随机数的方法,结果愣是整了半天没整出来,说来也是惭愧啊(亏我还是软件工程的学生,其实这个问题以前遇到过,只是我逃避了,哎,自己刨的坑终究会把自己陷进去,╮(╯▽ ...
- HTML input 标签不可编辑的 readonly 属性
1 <form action="form_action.asp" method="get"> Name:<input type="t ...
- winform 客户端 HTTP协议与服务端通信以及解决中文乱码
本来从来没有仔细研究过Http协议,今天因为公司业务需求,调试了半天,终于现在会Winform用Http协议与服务端通信了,其中常用的有POST和Get方式: 仔细看了人人网和新浪等大部分都是采用GE ...
- Java探索之旅(10)——数组线性表ArrayList和字符串生成器StringBuffer/StringBuilder
1.数组线性表ArrayList 数组一旦定义则不可改变大小.ArrayList可以不限定个数的存储对象.添加,插入,删除,查找比较数组更加容易.可以直接使用引用类型变量名输出,相当于toString ...
- 【推荐系统】Netflix 推荐系统:第二部分
原文链接:http://techblog.netflix.com/2012/06/netflix-recommendations-beyond-5-stars.htm 在 blog 的第一部分,我们详 ...
- 字符串(String)
字符串是由字符组成的数组,但在JavaScript中字符串是不可变的:可以访问字符串任意位置的文本,但是JavaScript并未提供修改已知字符串内容的方法. 常见功能: obj.length ...