codeforces 6B President's Office
2014-06-11 17:10
369 查看
B. President's Office
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
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.
题目大意就是,输入一个字符的矩阵表示办公室的布局,某个字符表示president的办公桌,求问他和他相邻的不同人有多少个(不包括8连通的相邻)。ps:已知办公室内,大家的桌子都是矩形的。
这题看输入,最大100*100,无脑扫描一遍就可以了。
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
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.
题目大意就是,输入一个字符的矩阵表示办公室的布局,某个字符表示president的办公桌,求问他和他相邻的不同人有多少个(不包括8连通的相邻)。ps:已知办公室内,大家的桌子都是矩形的。
这题看输入,最大100*100,无脑扫描一遍就可以了。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <stack> #include <map> #include <set> #include <queue> #include <algorithm> using namespace std; char mat[105][105]; int main() { int n, m; char c; scanf("%d %d %c", &n, &m, &c); for (int i = 0; i < n; i++) scanf("%s", mat[i]); pair<int, int> lt(-1, -1); pair<int, int> rb(-1, -1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (mat[i][j] == c){ rb = pair<int, int>(i, j); if (lt.first < 0) lt = pair<int, int>(i, j); } } } set<char> ans; for (int i = lt.first; i <= rb.first; i++) { for (int j = lt.second; j <= rb.second; j++) { if (i>0 && mat[i-1][j]!=c && mat[i-1][j]!='.') ans.insert(mat[i-1][j]); if (i< n-1 && mat[i+1][j]!=c && mat[i+1][j]!='.') ans.insert(mat[i+1][j]); if (j>0 && mat[i][j-1]!=c && mat[i][j-1]!='.') ans.insert(mat[i][j-1]); if (j<m-1 && mat[i][j+1]!=c && mat[i][j+1]!='.') ans.insert(mat[i][j+1]); } } printf("%d\n", ans.size()); return 0; }
相关文章推荐
- codeforces 6B. President's Office
- CodeForces 6B President's Office
- Codeforces 630B Moore's Law
- CodeForces 630 B. Moore's Law(快速幂)
- Codeforces 235B Let's Play Osu!
- Codeforces 235B Let's Play Osu! 概率dp(水
- CodeForces 118D Caesar's Legions
- CodeForces 6B - President's Office
- CodeForces 614 B. Gena's Code(水~)
- CodeForces 534C Polycarpus' Dice 【数学】
- CodeForces 9C Hexadecimal's Numbers(DFS)
- Codeforces 768A Oath of the Night's Watch
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
- codeforces 397A On Segment's Own Points-yy
- 51nod 1536不一样的猜数游戏 O(n)素数筛选法。同Codeforces 576A Vasya and Petya's Game。
- CodeForces 6B President's Office
- CodeForces 620 A. Professor GukiZ's Robot(水~)
- CodeForces 9C - Hexadecimal's Numbers
- codeforces 630B Moore's Law
- CodeForces 626D Jerry's Protest+思维题