Educational Codeforces Round 5 - C. The Labyrinth (dfs联通块操作)
题目链接:http://codeforces.com/contest/616/problem/C
题意就是 给你一个n行m列的图,让你求’*‘这个元素上下左右相连的连续的’.‘有多少(本身也算一个),每个’*‘的结果取模10。要是为’*‘输出结果,否则输出’.‘。
这个题目就是让你求连续的'.'联通块元素个数,求完一个联通块就把这个联通块标个记号(我设了ok[][]二维数组 表示这个位置的元素的联通块的标号,相连的则为同一个标号),之后这个联通块的每个元素的ans都为f(f为联通块元素个数),然后把这些dfs过的联通块标记为经过即可。当你求’*‘周围联通的’.‘个数的时候 判断上下左右的ok[][]数组是否一样,再加ans[][]答案就好。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set> using namespace std;
const int MAXN = 1e3 + ;
char map[MAXN][MAXN];
int tox[] = {- , , , } , toy[] = { , - , , } , m , n;
int ok[MAXN][MAXN] , f , cont[MAXN * MAXN];
typedef pair <int , int> P;
vector <P> v; bool judge(int x , int y) {
if(map[x][y] == '.' && !ok[x][y] && x >= && x < n && y >= && y < m) {
return true;
}
return false;
} void dfs(int x , int y) {
for(int i = ; i < ; i++) {
if(judge(x + tox[i] , y + toy[i])) {
v.push_back(P(x + tox[i] , y + toy[i]));
ok[x + tox[i]][y + toy[i]] = f;
dfs(x + tox[i] , y + toy[i]);
}
}
} int main()
{
f = ;
ios::sync_with_stdio(false);
set <int> s;
cin >> n >> m;
for(int i = ; i < n ; i++) {
cin >> map[i];
}
memset(ok , , sizeof(ok));
memset(cont , , sizeof(cont));
for(int i = ; i < n ; i++) {
for(int j = ; j < m ; j++) {
if(!ok[i][j] && map[i][j] == '.') {
ok[i][j] = f;
v.clear();
v.push_back(P(i , j));
dfs(i , j);
cont[f++] = v.size();
}
}
}
int temp = ;
for(int i = ; i < n ; i++) {
for(int j = ; j < m ; j++) {
if(map[i][j] == '*') {
temp = ;
s.clear();
for(int k = ; k < ; k++) {
int x = tox[k] + i , y = toy[k] + j;
if(map[x][y] == '.' && x >= && y >= && y < m && x < n) {
s.insert(ok[x][y]);
}
}
set<int>::iterator it = s.begin();
for( ; it != s.end() ; it++) {
temp += cont[int(*it)];
}
cout << temp % ;
}
else {
cout << '.';
}
}
cout << endl;
}
}
Educational Codeforces Round 5 - C. The Labyrinth (dfs联通块操作)的更多相关文章
- Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集
C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 5
616A - Comparing Two Long Integers 20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 53 E. Segment Sum(数位DP)
Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...
- Educational Codeforces Round 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- Educational Codeforces Round 21
Educational Codeforces Round 21 A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...
- Educational Codeforces Round 43
Educational Codeforces Round 43 A. Minimum Binary Number 显然可以把所有\(1\)合并成一个 注意没有\(1\)的情况 view code / ...
- Educational Codeforces Round 17
Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...
随机推荐
- objcopy
objcopy objcopy [options] infile [outfile] Copy the contents of the input object file to another fil ...
- JS省队集训记
不知不觉省队集训已经结束,离noi也越来越近了呢 论考前实战训练的重要性,让我随便总结一下这几天的考试 Day 1 T1 唉,感觉跟xj测试很像啊?meet in middle,不过这种题不多测是什么 ...
- UVa 11330 (置换 循环的分解) Andy's Shoes
和UVa11077的分析很类似. 我们固定左脚的鞋子不动,然后将右脚的鞋子看做一个置换分解. 对于一个长度为l的循环节,要交换到正确位置至少要交换l-1次. #include <cstdio&g ...
- windows2003 IIS6网络负载平衡设置
问题 随着计算机技术的不断发展,单台计算机的性能和可靠性越来越高.但现实中还是有许多应用是单台计算机难以达到,例如: 1.银行存储用户数据的数据库服务器必须保证24小时不间断的运转,并在发生严重硬件故 ...
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
这些方法调用的先后顺序如下(使用 replaceScene 方法): 1. 第2个场景的 scene 方法 2. 第2个场景的 init 方法 3. 第2个场景的 onEnter 方法 4. 转场 5 ...
- Java [Leetcode 232]Implement Queue using Stacks
题目描述: Implement the following operations of a queue using stacks. push(x) -- Push element x to the b ...
- Please ensure that adb is correctly located at……问题解决方案
启动android模拟器时.有时会报The connection to adb is down, and a severe error has occured.的错误.在网友说在任务管理器上把所有ad ...
- MySQL基础之第1章 数据库概述
1.1.数据存储方式 1.人工管理阶段2.文件系统阶段3.数据库系统阶段 1.2.数据库泛型 数据库泛型就是数据库应该遵循的规则.数据库泛型也称为范式.目前关系数据库最常用的四种范式分别是:第一范式( ...
- ASP.NET CORE Web浏览器和Web服务器
//web浏览器 //浏览器本质的原理:浏览器向服务器发请求,服务器把请求的内容返回给浏览器,然后浏览器把返回的内容绘制成一个图形化的界面 //Socket一种通讯交流的技术 //qq用户把信息通过s ...
- 关于ThinkPHP中Session不能夸模块/控制器使用的问题-网上的答案我做个补充
1,确保c:/windows目录下有php.ini文件2,修改php.ini中的session.auto_start = 0 为 session.auto_start = 1 //设置自动开启ses ...