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 ...
随机推荐
- .ui/qrc文件自动生成.py文件
前天PL让我们做一个从手机里手机一些数据导出到excel文件里的Tool. 让我们用python去写一个.但是我们都没有学过python..呵呵! 然后昨天看了一些文档.做ui时还需要把图片写入qrc ...
- python基础之常用内置函数
前言 python有许多内置的函数,它们定义在python的builtins模块,在python的代码中可以直接使用它们. 常用的内置函数 类型转换 int python的整数类型都是int类型的实例 ...
- svn add --no-ignore
提交新代码时:svn add --no-ignore /dir 不加的话可能会漏提交某些依赖或文件. Svn st -q --no-ignore. 提交时不需要加
- centos上git搭建
1 git的安装需要一些包: yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-Ex ...
- angular项目中使用jQWidgets
Angular CLI with jQWidgets In this tutorial, we will show you how to use https://cli.angular.io/ alo ...
- [ python ] 练习作业 - 2
1.写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者. lic = [0, 1, 2, 3, 4, 5] def func(l): return l[1::2 ...
- SilverLight 浏览器出现滚动条
照网上说的很多解决方案要不得,最后想了下,直接在body上面加 style="overflow:hidden"解决问题,真觉得微软管理混乱,很多它自己的东西都不支持了.
- 对于ntp.conf的理解
允许与我们的时间源同步时间,但是不允许源查询或修改这个系统上的服务. # Permit time synchronization with our time source, but do not # ...
- CSS背景横向平铺BUG,解决方法
给定DIV一个背景图片横向平铺,缩小浏览器,拉动横向滚动条,此时触发此BUG:背景图片平铺不完整 解决办法: 1.把背景图片写在BODY上,此办法局限于没有使用iframe的情况下,所以少用 2.设定 ...
- Codeforces 351D Jeff and Removing Periods(莫队+区间等差数列更新)
题目链接:http://codeforces.com/problemset/problem/351/D 题目大意:有n个数,每次可以删除掉数值相同并且所在位置成等差数列的数(只删2个数或者只删1个数应 ...