zoukankan      html  css  js  c++  java
  • 选择题(codevs 2919)

    2919 选择题

     

     时间限制: 1 s
     空间限制: 16000 KB
     题目等级 : 黄金 Gold
     
     
    题目描述 Description

    某同学考试,在N*M的答题卡上写了A,B,C,D四种答案。

    他做完了,又不能交,一看表,离打铃还有N久。

    他开始玩一个游戏:选一个格子X,Y,从这个格子出发向4个方向找相同的选项,找到的再如此。

    求形成的图形的面积。(一个选项占一个单位面积)

    输入描述 Input Description

    N M X  Y

    答题卡(矩阵)

    输出描述 Output Description

    面积

    样例输入 Sample Input

    3 3 1 2

    A C B

    C C C

    D C A

    样例输出 Sample Output

    5

    数据范围及提示 Data Size & Hint

    N,M<=15.

    对于33%数据,只有A。

    #include<cstdio>
    #include<iostream>
    #define M 16
    using namespace std;
    char map[M][M];
    int vis[M][M],n,m,ans,flag;
    int a[5]={0,0,0,1,-1};
    int b[5]={0,-1,1,0,0};
    char cc;
    int out(int x,int y)
    {
        if(x>n||x<1||y>m||y<1)return 1;
        if(map[x][y]!=cc||vis[x][y])return 1;
        return 0;
    }
    void dfs(int x,int y)
    {
        if(out(x+1,y)&&out(x,y+1)&&out(x-1,y)&&out(x,y-1))
          return;
        for(int i=1;i<=4;i++)
        {
            int xx=x+a[i];
            int yy=y+b[i];
            if(!out(xx,yy))
            {
                ans++;
                vis[xx][yy]=1;
                dfs(xx,yy);
            }
        }
    }
    int main()
    {
        int x,y;
        scanf("%d%d%d%d",&n,&m,&x,&y);
        for(int i=1;i<=n;i++)
          for(int j=1;j<=m;j++)
            cin>>map[i][j];
        cc=map[x][y];
        dfs(x,y);
        printf("%d",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    windows常用快捷键
    【Linux】查看系统位数
    【Centos】yum 安装mariaDB
    【Centos7 GRUB】修改开机等待时间
    Shell脚本编写规范
    【Shell Basic】source . 与 bash sh 的区别
    linux防火墙之 ufw
    【HotSpot】jps命令行详解
    【Ubuntu 16】网络配置文件
    【刷题】BZOJ 2179 FFT快速傅立叶
  • 原文地址:https://www.cnblogs.com/harden/p/5581837.html
Copyright © 2011-2022 走看看