CF_6B_President'sOffice
来源:互联网 发布:淘宝客服平均工资 编辑:程序博客网 时间:2024/06/05 12:03
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.
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.
Print the only number — the amount of President's deputies.
3 4 RG.B..RR.TTT.
2
3 3 Z....H...Z
0
一个办公室里有好多矩形桌子
不同桌子不同颜色
给出总统的桌子的颜色
总统的副手的桌子跟总统的桌子相邻
问有多少个副手
找到总统的桌子
然后顺着桌子边缘找一圈即可
#include <iostream>#include <stdio.h>#include <map>using namespace std;const int M=105;char ti[M][M];map<char,int>ma;int main(){ int n,m; char ss[M],pr; int l,r,u,d; //president的桌子占得位置 scanf("%d%d%s",&n,&m,ss); pr=ss[0]; for(int i=1;i<=n;i++) scanf("%s",ti[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(ti[i][j]==pr) { l=j,u=i; for(;;i++) if(ti[i][j]!=pr) { i--; //cout<<" 1111"; break; } d=i; for(;;j++) if(ti[i][j]!=pr) { j--; //cout<<" 1111"; break; } r=j; } } //cout<<l<<r<<u<<d; if(u>1) for(int i=l;i<=r;i++) if('A'<=ti[u-1][i]&&ti[u-1][i]<='Z') ma[ti[u-1][i]]++; if(d<n) for(int i=l;i<=r;i++) if('A'<=ti[d+1][i]&&ti[d+1][i]<='Z') ma[ti[d+1][i]]++; if(l>1) for(int i=u;i<=d;i++) if('A'<=ti[i][l-1]&&ti[i][l-1]<='Z') ma[ti[i][l-1]]++; if(r<m) for(int i=u;i<=d;i++) if('A'<=ti[i][r+1]&&ti[i][r+1]<='Z') ma[ti[i][r+1]]++; printf("%d\n",ma.size()); return 0;}
- CF_6B_President'sOffice
- soffice实现的文件上传转换
- www-data 不能执行 shell_exec soffice --convert-to
- 第三周项目3-设计倒三角形
- HDU 2153 仙人球的残影(类蛇形填数)
- hive中常量列的添加和查询
- Visual Studio环境变量使用实例:使用环境变量来组织工程
- 图片切换器:剖析Gallery和ImageSwitcher的一些细节
- CF_6B_President'sOffice
- 还是mysql的问题
- LightOJ 1197 - Help Hanzo (模拟筛素法区间筛素)
- IT行业导览-4.2-产品设计师
- 单向链表排序
- Java中权限修饰问题private -> protected -> (default) -> public
- 职场加薪步步高升的五大法则
- 34本设计师必看的书籍推荐
- VK Cup 2016 - Round 1 (Div. 2 Edition)C. Bear and Forgotten Tree 3(构造)