B. President's Office

题目连接:

http://codeforces.com/contest/6/problem/B

Description

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.

Sample Input

3 4 R

G.B.

.RR.

TTT.

Sample Output

2

Hint

题意

给你n,m,c表示n行m列的矩阵,c是主人公的桌子颜色

现在与主人公桌子接触的人的桌子是主人公的小弟。

问你这个主人公有多少个小弟。

题解:

直接暴力就好了……

对于每个主人公的桌子,都四处扫一扫就好了。

代码

#include<bits/stdc++.h>
using namespace std; map<char,int>H;
char s[120][120];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int ans;
int main()
{
int n,m;
char c;
cin>>n>>m>>c;
for(int i=1;i<=n;i++)
scanf("%s",s[i]+1);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(s[i][j]==c)
for(int k=0;k<4;k++)
{
int x=i+dx[k];
int y=j+dy[k];
if(x<=0||x>n)continue;
if(y<=0||y>m)continue;
if(s[x][y]==c)continue;
if(s[x][y]=='.')continue;
if(H[s[x][y]])continue;
ans++;
H[s[x][y]]++;
}
}
}
cout<<ans<<endl;
}

Codeforces Beta Round #6 (Div. 2 Only) B. President's Office 水题的更多相关文章

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  3. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  4. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  5. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  7. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  8. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  9. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

随机推荐

  1. 设计模式之Composite

    设计模式总共有23种模式这仅仅是为了一个目的:解耦+解耦+解耦...(高内聚低耦合满足开闭原则) Composite定义? 将对象以树形结构组织起来,以达成“部分-整体” 的层次结构. 想到Compo ...

  2. keypress 、keydown、keyup后触发回车

    1.keypress .keydown.keyup的区别 keypress表示键盘按下的全过程,只有按下任意字母数字键(后退.删除等系统功能键无效)时才触发,捕获到的keyCode区分大小写 keyd ...

  3. perl6 一个猜测密码的注入

    use HTTP::UserAgent; my $ua = HTTP::UserAgent.new; my $r = HTTP::Request.new; my $c = HTTP::Cookies. ...

  4. Three.js基础探寻五——正二十面体、圆环面等

    除了立方体.平面.球体,Three.js还提供了很多其他几何形状. 1.圆形 CircleGeometry可以创建圆形或者扇形: THREE.CircleGeometry(radius, segmen ...

  5. 41、和为S的连续正数序列

    一.题目 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久,他 ...

  6. python基础之上下文管理器

    前言 关于计算器运行的上下文的概念,我的理解也不是很深:按我的理解就是程序在运行之前,其所需要的资源,运行环境等都会被序列化,然后加入到CPU的任务队列中,等待调度系统分配时间片执行.下面谈谈pyth ...

  7. Python排序算法之插入排序

    # 插入排序的工作原理是,对于每个未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.## 步骤:## 从第一个元素开始,该元素可以认为已经被排序# 取出下一个元素,在已经排序的元素序列中从后 ...

  8. 混合式App开发 Apicloud 官方iPhone X 适配

    iPhone X 适配 由于iPhone X的特殊造型,为了方便开发者对iPhone X进行适配,苹果在iOS 11中引入了Safe Area的概念,引擎也在api对象下添加了safeArea属性和s ...

  9. MySQL-索引工作原理及使用注意事项

    1.为什么需要索引(Why is it needed)? 当数据保存在磁盘类存储介质上时,它是作为数据块存放.这些数据块是被当作一个整体来访问的,这样可以保证操作的原子性.硬盘数据块存储结构类似于链表 ...

  10. windows下安装多个mysql

    1.正常安装mysql5.1.33 安装服务名为mysql3306 安装目录d:\mysql5.1\3306 安装完成后,关闭服务 ① 复制安装文件 将默认安装目录C:\Documents and S ...