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. 转: oracle中schema指的是什么?

    看来有的人还是对schema的真正含义不太理解,现在我再次整理了一下,希望对大家有所帮助. 我们先来看一下他们的定义:A schema is a collection of database obje ...

  2. kernel随机生成MAC地址的接口

    /**  * eth_random_addr - Generate software assigned random Ethernet address * @addr: Pointer to a si ...

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

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

  4. jfinal文件上传

    jfianl获取表单数据,需要先getFile()获取文件,再使用getPara() public class ImageUploadController extends Controller{ pu ...

  5. 在eclipse中使用Maven3(笔记二)

    笔记本二   在Eclipse 中使用Maven 第一节:m2eclipse 插件安装 打开Eclipse,点击菜单Help - > Install New Software 点击Add 按钮N ...

  6. Erasure Coding(纠删码)深入分析 转

    1.前言 Swift升级到2.0大版本后宣称开始支持纠删码,这其实是一个很有意义的特性,主要是能够在一定程度上解决3副本空间浪费太多的问题.因为3副本这一点是swift推广的最大障碍之一,成本的增加吓 ...

  7. Android 下使用 JSON 实现 HTTP 请求,外加几个示例!

    不得不说,JSON 格式的确是非常美妙的,速度快而且简化了很多操作在 Android 下,Android SDK 已经为我们封装好了整个与 JSON 有关的操作,使用非常方便 以下就是一个标准的 JS ...

  8. Ntp时间服务器与定时任务Crontab

    一 NTP时间服务器 1 局域网内的NTP同步配置 注意 所有配置操作必须是root用户 ,局域网内node21作为NTP Server,node22,node23作为NTP Client与服务器进行 ...

  9. MySQL 中的日期时间类型

    日期时间类型中包含以下几种数据类型: DATE TIME DATETIME TIMESTAMP YEAR 各类型都有具体的取值范围,超出或非法的其他值时,MySQL 会回退到 0.TIMESTAMP ...

  10. Codeforces Round #345 (Div. 1) D - Zip-line 带单点修改的LIS 主席树 | 离线树状数组

    D - Zip-line #include<bits/stdc++.h> #define LL long long #define fi first #define se second # ...