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是主人公的桌子颜色

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

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

题解:

直接暴力就好了……

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

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. map<char,int>H;
  4. char s[120][120];
  5. int dx[4]={1,-1,0,0};
  6. int dy[4]={0,0,1,-1};
  7. int ans;
  8. int main()
  9. {
  10. int n,m;
  11. char c;
  12. cin>>n>>m>>c;
  13. for(int i=1;i<=n;i++)
  14. scanf("%s",s[i]+1);
  15. for(int i=1;i<=n;i++)
  16. {
  17. for(int j=1;j<=m;j++)
  18. {
  19. if(s[i][j]==c)
  20. for(int k=0;k<4;k++)
  21. {
  22. int x=i+dx[k];
  23. int y=j+dy[k];
  24. if(x<=0||x>n)continue;
  25. if(y<=0||y>m)continue;
  26. if(s[x][y]==c)continue;
  27. if(s[x][y]=='.')continue;
  28. if(H[s[x][y]])continue;
  29. ans++;
  30. H[s[x][y]]++;
  31. }
  32. }
  33. }
  34. cout<<ans<<endl;
  35. }

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. cookie 跨域的问题

    今天研究一天发现cookie无法设置除当前域名或者其父域名之外的其他domain. 这个是浏览器出于对cookie的保护造成的,也就是cookie无法跨域设置. 对于子域名也有如下规则,当前域名只能设 ...

  2. Git和Github简单教程【转】

    转自:https://www.cnblogs.com/schaepher/p/5561193.html#clone 原文链接:Git和Github简单教程 网络上关于Git和GitHub的教程不少,但 ...

  3. juery获取元素的方法

    1 从集合中通过指定的序号获取元素 html: 复制代码 代码如下: <div> <p>0</p> <p>1</p> <p>2& ...

  4. mysql root 密码恢复

    1.停止mysql服务 service mysql stop 2.启动mysql时不启动授权表,跳过权限验证使用空密码登陆 mysqld_safe --skip-grant-tables & ...

  5. 3.rabbitmq 发布/订阅

    1. 发布者 #coding:utf8 import pika import json import sys message = ''.join(sys.argv[1:]) or "hell ...

  6. 使用Guava retryer优雅的实现接口重试机制

    转载自: 使用Guava retrying优雅的实现接口重调机制 Guava retrying:基于 guava 的重试组件 实际项目中,为了考虑网络抖动,加锁并发冲突等场景,我们经常需要对异常操作进 ...

  7. 8. Docker Machine

  8. 如何使用OpenSSL工具生成根证书与应用证书

    如何使用OpenSSL工具生成根证书与应用证书 一.步骤简记 // 生成顶级CA的公钥证书和私钥文件,有效期10年(RSA 1024bits,默认) openssl req -new -x509 -d ...

  9. 【Mac 10.13.0】安装 libimobiledevice,提示报错:warning: unable to access '/Users/lucky/.config/git/attributes': Permission denied解决方案

    打开终端,执行命令: 1.sudo chown -R XXX /usr/local  (XXX表示当前用户名) 2.ruby -e "$(curl -fsSL https://raw.git ...

  10. Oracle 入门学习笔记

    linux命令 查看linux系统版本号 uname -r 或 uname -a 查看linux发行版本号 cat /etc/redhat-release 查看linux具体版本号 cat /proc ...