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 ...
随机推荐
- C/C++内存存储
#include <stdio.h> #include "string.h" #include "malloc.h" void Swap(int a ...
- 1930. Ivan's Car(spfa)
1930 简单二维 标记一下是上坡还是下坡 #include <iostream> #include<cstdio> #include<cstring> #incl ...
- ZOJ 1610 Count the Colors (线段树 成段更新)
题目链接 题意:成段染色,初始为0,每次改变一个区间的颜色,求最后每种颜色分别有多少段.颜色按照从 小到大输出. 分析:改变了代码的风格,因为看了学长的博客.直接用数组,可以只是记录节点的编号,因为节 ...
- Android中使用广播机制退出多个Activity
谷歌百度一下,Android中退出多个Activity的方法,大家讨论的很多. 在实习的时候,看到公司的项目退出多个Activity,是采用LinkedList方法,毕业设计的时候,也参照了那种方法. ...
- tomcat发布web service教程
这几天一直在准备找工作,自学了关于web service的一些基本的内容,也遇到了不少问题.现在就把我自己学到的知识和大家分享一下,由于是初学,所以有什么错误的地方请大家帮忙指正,感激不尽~~!! 1 ...
- 函数fsp_try_extend_data_file
扩展表空间 /***********************************************************************//** Tries to extend t ...
- MyBatis 实践 -配置
MyBatis 实践 标签: Java与存储 Configuration mybatis-configuration.xml是MyBatis的全局配置文件(文件名任意),其配置内容和顺序如下: pro ...
- js 时间转成时间戳对比;My97DatePicker日历控件时间格式;Date.parse Firefox火狐浏览器返回Nan的解决办法
有个情况,我在显示时间的时候是需要显示为 2013年8月15日 14时28分15秒 但是假如我用js去获取到这个时间,并且想进行时间对比的时候,这个时间2013年8月15日 14时28分15秒根本就 ...
- HelloX操作系统与中国移动OneNET物联网平台成功完成对接
HelloX成功与中国移动物联网平台对接 经过HelloX项目组同仁的努力,尤其是Tywin(@飓风)的努力下,HelloX最新版本V1.78已成功与中国移动OneNET(open.iot.10086 ...
- 众神看过来:IE11下鼠标中键(滚轮)导致的一个似乎无法解决的问题?!
最近在做asp.net mvc项目时遇到一个关于超链接的问题.很是纠结. 问题描述 有一个公司列表展示页.在用鼠标中键(注意了是滚轮)以下简称中键,点击编辑(超链接)的时候在该条数据的下面直接加在一个 ...