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 ...
随机推荐
- 用C#实现对MSSqlServer数据库的增删改查---Server层(WaterLevelRecordServer.cs、DeviceRecordServer.cs)
抛开现实的残酷与无奈,对技术孜孜不倦的追求,从专注到执着,从疯狂到忘我,始终坚信代码可以改变世界,更能改变自己的人生. WaterLevelRecordServer.cs using System; ...
- C#调用mciSendString播放音频文件
mciSendString函数是一个WinAPI,主要用来向MCI(Media Control Interface)设备发送字符串命令. 一.函数的声明如下: private static exter ...
- 使用xbee连接地面站和飞控
Zigbee是一种短距离.低功耗的近距离无线组网通讯技术,主要适用于自动控制和远程控制领域,可以嵌入各种设备. DIGI的ZigBee产品XBee小型但却是一个功能完善的ZigBee收发器(即接收器/ ...
- 自己实现的SVM源码
首先是DATA类 import java.awt.print.Printable; import java.io.File; import java.io.FileNotFoundException; ...
- 用socket发送匿名邮件之python实现
发送邮件可以用smtp协议,整个过程为: 用户代理(user-agent,比如outlook.foxmail等邮件客户端)---(smtp协议)--->本地邮件服务器 --- (smtp协议)- ...
- php正则匹配以“abc”开头且不能以“xyz”结尾的字符串
本文介绍下,用php正则区配以"abc"开头的,且不能以"xyz"结尾的字符串的方法,有需要的朋友参考下. 要求:用php正则表达式匹配以“abc”开头,但结尾 ...
- hdu5984
听说大佬都是看到1.693147就知道是ln(2)+1我是服气的 不过老老实实推的话就看你大一数分/高数是不是学扎实了 令 把L移到右边并两边求导可得,即 令 代入最开始的公式得到 化简可得,得解 # ...
- 第 17 章 使用API
在本章中,我们将学习如何编写一个独立的程序,并对其获取的数据进行可视化.这个程序将使用Web应用编程接口(API)自动请求网站的特定信息而不是整个网页,再对这些信息进行可视化.由于这样编写的程序始终使 ...
- Linux文件系统的详解
这里以 EXT2 文件系统为例 在Linux下,一个磁盘的最前面是MBR,大小为512Byte 在每一个分区下,第一部分是boot sector,接下来是super block,再接下来是inode, ...
- lr中用strtok函数分割字符串
需要在loadrunner里面获得“15”(下面红色高亮的部分),并做成关联参数. ,6,5,0,4,0,3,0,3,2,0,0,0,1 用web_reg_save_param取出“8,7,5,15, ...