President's Office
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Example
3 4 R
G.B.
.RR.
TTT.
2
3 3 Z
...
.H.
..Z
0 题意:找给出颜色周围有多少种不同颜色
#include <iostream>
#include <stdio.h>
using namespace std;
int n, m;
char p;
char Map[][];
int col[];
int ans = ;
int dir[][] = {,,,,-,,,-}; void dfs(int x, int y){
for(int i = ; i < ; i ++){
int xx = x + dir[i][];
int yy = y + dir[i][];
if(xx >= && xx < n && yy >= && yy < m){
if(col[Map[xx][yy]] == && Map[xx][yy] != '.'){
ans++;
col[Map[xx][yy]] = ;
}
}
}
} int main(){
cin >> n >> m;
getchar();
p = getchar();
col[p] = ;
for(int i = ; i < n; i++){
for(int j = ; j < m; j++){
cin >> Map[i][j];
}
}
for(int i = ; i < n; i++){
for(int j = ;j < m; j++){
if(Map[i][j] == p){
dfs(i,j);
}
}
}
cout << ans << endl;
}
President's Office的更多相关文章
- Codeforces Beta Round #6 (Div. 2 Only) B. President's Office 水题
B. President's Office 题目连接: http://codeforces.com/contest/6/problem/B Description President of Berla ...
- CF6B President's Office 题解
看到大致思路一致的题解,决定发一篇运用STL不用dfs的题解 好久不发题解,心里不爽 思路: 1.输入的同时找到总统桌子的位置,用vector<pair <int,int> ...
- CUGBACM Codeforces Tranning 3 题解
链接:http://acm.hust.edu.cn/vjudge/contest/view.action? cid=62515#overview 描写叙述:第三场CF训练了.这次做的挺搞笑的,我记得这 ...
- 经济-AMA:百科
ylbtech-经济-AMA:百科 美国市场营销协会(American Marketing Association,简称AMA)于1937年由市场营销企业界及学术界具有远见卓识的人士发起成立.如今,该 ...
- .NET Core 首例 Office 开源跨平台组件(NPOI Core)
前言 最近项目中,需要使用到 Excel 导出,找了一圈发现没有适用于 .NET Core的,不依赖Office和操作系统限制的 Office 组件,于是萌生了把 NPOI 适配并移植到 .NET C ...
- [.NET] 打造一个很简单的文档转换器 - 使用组件 Spire.Office
打造一个很简单的文档转换器 - 使用组件 Spire.Office [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/6024827.html 序 之前,& ...
- 高效而稳定的企业级.NET Office 组件Spire(.NET组件介绍之二)
在项目开发中,尤其是企业的业务系统中,对文档的操作是非常多的,有时几乎给人一种错觉的是”这个系统似乎就是专门操作文档的“.毕竟现在的很多办公中大都是在PC端操作文档等软件,在这些庞大而繁重的业务中,单 ...
- 在禅道中实现WORD等OFFICE文档转换为PDF进行在线浏览
条件: 安装好禅道的服务器 能直接浏览PDF的浏览器(或通过 安装插件实现 ) 文档转换服务程序(建议部署在另一台服务器上) 实现 原理: 修改禅道的文件预览功能(OFFICE文档其使用的是下 ...
- RMS:Microsoft Office检测到您的信息权限管理配置有问题。有关详细信息,请与管理员联系。(转)
原文:https://zhidao.baidu.com/question/435088233.html RMS有两种方式: 1.使用微软的服务器,这个是连接到微软的服务器上面做权限控制,在今年5月份之 ...
随机推荐
- centos7.x修改网卡名字
1.编辑/etc/default/grub 加入如下代码 net.ifnames=0 biosdevname=0 2. 在执行以下 grub2-mkconfig -o /boot/grub2/gru ...
- Excel 整个列数字转换成文本
选中该列----数据---分列----下一步---到步骤三----列数据格式---勾选"文本"---完成.
- go module 命令
项目目录下,执行以下命令初始化 go mod init 执行以下命令会自动分析项目里的依赖关系同步到go.mod文件中,同时创建go.sum文件 go mod tidy 以上的管理依赖管理操作,所以依 ...
- linux中weblogic相关命令操作
在weblogic的目录下找到bin目录,其中有startWeblogic.sh.startManagerWeblogic.sh等 首先需要启动startWeblogic.sh,这个是管理服务,也就是 ...
- usb-blaster安装
插入usb-blaster后,无法安装驱动,一直显示感叹号,更新驱动后显示“文件的哈希值不在指定的目录”这样的错误提示,解决方法如下:1.Windows键+ R,输入shutdown.exe /r / ...
- 【C++】c++11多线程初探
相关头文件c++11 新标准中引入了四个头文件来支持多线程编程,他们分别是<atomic> ,<thread>,<mutex>,<condition_vari ...
- Ext.require 的作用(转)
Ext.require:用到哪些组件,然后就预先加载,多余不用加载的组件 在实际环境中我们都会用 ext-all.js, 但是在开发调试的时候,我们使用 require 的话它可以动态加载单个的 js ...
- springboot logback
/resources/logback-spring.xml <configuration> <appender name="stdout" class=" ...
- springboot找不到主类
在学习springboot的时候,前几天写了一个demo,正常运行,一点问题也没有.今天运行不起来了. 报错:找不到主类 解决方案: Project->Clean->选中项目,点击Clea ...
- Jasper打印示例
import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List ...