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 ...
随机推荐
- poj 2828 Buy Tickets (线段树)
题目:http://poj.org/problem?id=2828 题意:有n个人插队,给定插队的先后顺序和插在哪个位置还有每个人的val,求插队结束后队伍各位置的val. 线段树里比较简单的题目了, ...
- Android中View转换为Bitmap及getDrawingCache=null的解决方法
1.前言 Android中经常会遇到把View转换为Bitmap的情形,比如,对整个屏幕视图进行截屏并生成图片:Coverflow中需要把一页一 页的view转换为Bitmap.以便实现复杂的图形效果 ...
- ganglia对于tomcat进程的res内存监控扩展
ganglia是采用yum的安装,因此安装相关内容路径可能不同,但是不影响插件的扩展编写: 本次介绍的扩展是采用python脚本进行扩展,因此监控节点上需要安装python的相关插件: sudo yu ...
- C#计算程序执行速度
long t1 = DateTime.Now.Ticks; //执行程序,例如处理100个文件 long t2 = DateTime.Now.Ticks; Response.Write("执 ...
- Fatal NI connect error 12170
Fatal NI connect error 12170 转载:http://www.xifenfei.com/1812.html 今天在一台服务器的日志文件中,发现如下信息: Fatal NI co ...
- Redis必要的一些配置
[root@localhost202 redis-2.8.19]# /usr/local/redis/bin/redis-server >> /data/redis-start.txt ...
- UVA 11090 Going in Cycle!!(二分答案+判负环)
在加权有向图中求平均权值最小的回路. 一上手没有思路,看到“回路”,第一想法就是找连通分量,可又是加权图,没什么好思路,那就转换题意:由求回路权值->判负环,求最小值->常用二分答案. 二 ...
- System.arraycopy方法
数组的复制有多种方法,其中有一种就是System.arraycopy方法,传闻速度也很快. 方法完整签名: public static void arraycopy(Object src, int s ...
- xp重装系统后恢复Linux启动
我的电脑----右键-----属性----高级----启动与恢复故障----设置编辑 [boot loader]timeout=3default=multi(0)disk(0)rdisk(0)part ...
- C#网络资源列表
1, http://club.topsage.com/thread-371996-1-1.html