zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    <li>标签在ie6下的上下间隔的BUG解决办法
    win7 瘦身 减肥 记录!
    学习系统封装半年经验总结!
    DIV 类似 hover 悬停效果 鼠标移动上去变化
    解决 WIN7 部署 安装驱动包时出现的驱动签名提示 办法!
    Windows 7 瘦身大全 系统减肥 轻松 瘦身 减肥 3个G
    JS 判断 取 当前系统类型 可用来定义某些WIN7系统和XP系统下字体区别
    JS 判断 当前浏览器类型
    EasyBoot常用的命令
    Win7封装保持任务栏锁定项不变的解决方法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5353128.html
Copyright © 2011-2022 走看看