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 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 水题的更多相关文章
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
随机推荐
- http状态码说明
在学习网页设计的时候都应该知道状态码,但我们常见的状态码都是200,404,下面介绍其他的状态值 1开头的http状态码表示临时响应并需要请求者继续执行操作的状态代码. 100 (继续) 请求者应 ...
- python是如何进行内存管理的?
Python内存管理机制 Python内存管理机制主要包括以下三个方面: 引用计数机制 垃圾回收机制 内存池机制 引用计数 举个例子说明引用是什么: 1 如上为一个简单的赋值语句,1就是对象,a就是引 ...
- acm专题--并查集
题目来源:http://hihocoder.com/problemset/problem/1066 #1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256M ...
- 数据库连接池(c3p0与druid)
1.数据库连接池概念 其实就是一个容器(集合),存放数据库连接的容器.当系统初始化好后,容器被创建,容器中会申请一些连接对象,当用户来访问数据库时,从容器中获取连接对象,用户访问完之后,会将连接对象归 ...
- 【转+整理+答案】python315+道面试题
提示 自己整理的答案,很局限,如有需要改进的地方,或者有更好的答案,欢迎提出! [合理利用 Ctrl+F 提高查找效率] 第一部分 Python基础篇(80题) 1.为什么学习Python? # 因为 ...
- Windows下的字体美化
转自HJK的博客 许多人钟情于Mac很大一部分是因为Mac优雅的字体渲染,Windows原生的效果很难做得到,即便是开启了CleartType效果也不尽如人意.不论是微软本身的审美原因还是历史包袱,与 ...
- **[权限控制] 利用CI钩子实现权限认证
http://codeigniter.org.cn/forums/thread-10877-1-1.html 一直没找到CI的权限认证扩展,以前好像找到过一个老外的扩展,不过不怎么好用,现在记不清了, ...
- mvc部署
权限中加入windows 2008中加入SERVICE,windows2003中加入NETWORK SERVICE
- JS循环、数组与练习题
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- CoreOS中随着系统启动Docker Container
Start containers automatically https://docs.docker.com/engine/admin/host_integration/ https://www.fr ...