F - President's Office

本文深入探讨了总统办公室的布局及其对团队配置的影响,通过矩阵描述揭示了不同颜色的办公桌之间的相邻关系,进而计算出总统的副手数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

F - President's Office
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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 nm (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

Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
#include<iostream>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <numeric>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
#define Exp 1e-8
#define inf 0x7fffffff
#define Read freopen("in.txt","r",stdin)
#define Write freopen("out.txt","w",stdout)
#define maxn 55
#define mod 1000000007

int main()
{
   int M,N;
   int m[300]={0};           //字母的ASCII码-‘A’,作为下标
   char c,Map[300][300]={0};//办公室用Map储存
   scanf("%d%d %c",&M,&N,&c);
   getchar();          
   for(int i=1;i<=M;i++)
   {
       for(int j=1;j<=N;j++)
           scanf("%c",&Map[i][j]);
       getchar();
   }
for(int i=1;i<=M;i++)//遍历每个角落
   {
       for(int j=1;j<=N;j++)
       {
           if(Map[i][j]==c)//找到President 的办公桌
           {
               int mc;
               mc=Map[i-1][j]-'A';//前面的位置
               m[mc]++;            //记录对应字母的数量
               mc=Map[i][j-1]-'A';//左边的位置
               m[mc]++;            //记录对应字母的数量
               mc=Map[i+1][j]-'A';//后面的位置
               m[mc]++;            //记录对应字母的数量
               mc=Map[i][j+1]-'A';//右面的位置
               m[mc]++;            //记录对应字母的数量
           }
       }
   }
int s=0;
   for(int i=0;i<26;i++)
       if(m[i]&&i!=c-'A')  //统计有多少个字母被记录
           s++;
       cout<<s<<endl;  //这就是助手的人数
       return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值