题目链接: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联通块操作)的更多相关文章

  1. 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 ...

  2. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  3. Educational Codeforces Round 5

    616A - Comparing Two Long Integers    20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...

  4. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

  5. Educational Codeforces Round 53 E. Segment Sum(数位DP)

    Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...

  6. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  7. Educational Codeforces Round 21

    Educational Codeforces Round 21  A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...

  8. Educational Codeforces Round 43

    Educational Codeforces Round 43  A. Minimum Binary Number 显然可以把所有\(1\)合并成一个 注意没有\(1\)的情况 view code / ...

  9. Educational Codeforces Round 17

    Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...

随机推荐

  1. ie6调试工具Debugbar

    http://www.my-debugbar.com/wiki/Doc/DebugbarInstall

  2. 宏HASH_GET_FIRST

    /*******************************************************************//** Gets the first struct in a ...

  3. BZOJ2693: jzptab

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2693 题意:同2154 多组数据 题解:按2154再往后转化一下就可以把n,m放到一边儿,然后 ...

  4. MySQL基础之第11章 插入、更新与删除数据

    11.1.插入数据 11.1.1.为表的所有字段插入数据 1.INSERT语句中不指定具体的字段名         insert into 表名 values (值1,值2…值n)2.INSERT语句 ...

  5. [Everyday Mathematics]20150109

    设 $A$ 是 $n$ 阶复方阵, 其特征多项式为 $$\bex f(\lm)=(\lm-\lm_1)^{n_1}\cdots(x-\lm_s)^{n_s}, \eex$$ 其中 $\lm_i$ 互不 ...

  6. Permutations java实现

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  7. ylbtech-权限管理-数据库设计-功能权限管理技术

    ylbtech-DatabaseDesgin:ylbtech-权限管理-数据库设计-功能权限管理技术 DatabaseName:ylb_permission(权限管理-功能权限管理技术)实现 Type ...

  8. DBCP连接池原理分析及配置用法

    DBCP连接池介绍 ----------------------------- 目前 DBCP 有两个版本分别是 1.3 和 1.4. DBCP 1.3 版本需要运行于 JDK 1.4-1.5 ,支持 ...

  9. poj 3311 Hie with the Pie

    floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Me ...

  10. Tkinter教程之Text篇(3)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811348 '''Tkinter教程之Text篇(3)''''''14.自定义tag的两个内置 ...