zoukankan      html  css  js  c++  java
  • HDU 1312 Red and Black (第一道广搜)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1312

    大意:从@出发,只能站在不能站在#上。。。。求能踩到的.的个数(包括起始点@)

    #include <set>
    #include <map>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cctype>
    #include <cstring>
    #include <sstream>
    #include <fstream>
    #include <cstdlib>
    #include <cassert>
    #include <iostream>
    #include <algorithm>

    using namespace std;
    //Constant Declaration
    /*
    --------------------------*/
    //#define LL long long
    #define LL __int64
    const int M = 100;
    const int INF = 1<<30;
    const double EPS = 1e-11;
    const double PI = acos(-1.0);
    /*--------------------------*/
    // some essential funtion
    /*
    ----------------------------------*/
    void Swap(int &a,int &b){ int t=a;a=b;b=t; }
    int Max(int a,int b){ return a>b?a:b; }
    int Min(int a,int b){ return a<b?a:b; }
    int Gcd(int a,int b){ while(b){b ^= a ^=b ^= a %= b;} return a; }
    /*----------------------------------*/
    //for (i = 0; i < n; i++)
    /*
    ----------------------------------*/


    char g[M][M];
    int to[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    int n, m;

    struct Point
    {
    int x, y;
    };

    int Bfs(int x, int y)
    {
    int sum = 1;
    int i;
    queue <Point> Q;
    Point a, front, go;
    a.x = x;
    a.y = y;
    Q.push(a);
    g[x][y] = '#';
    while (!Q.empty())
    {
    front = Q.front();
    Q.pop();
    for (i = 0; i < 4; i++)
    {
    go.x = front.x + to[i][0];
    go.y = front.y + to[i][1];
    if (go.x>=0 && go.x<n && go.y>=0 && go.y<m && g[go.x][go.y] == '.')
    {
    sum++;
    Q.push(go);
    g[go.x][go.y] = '#';//关键
    }
    }
    }
    return sum;
    }


    int main()
    {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //int t, case1 = 0;
    //scanf("%d", &t);

    int i, j;
    int x, y;
    while (scanf("%d%d", &m, &n), n+m)
    {
    for (i = 0; i < n; i++)
    {
    for (j = 0; j < m; j++)
    {
    scanf(" %c", &g[i][j]);
    if (g[i][j] == '@')
    {
    x = i;
    y = j;
    }
    }
    }
    printf("%d\n", Bfs(x, y));
    }

    return 0;
    }



  • 相关阅读:
    windows查询占用端口的pid以及查询对应的进程名称
    [转]Android学习系列(29)App调试的几个命令实践
    [原]Android中接入微信客户端心得
    Robots.txt使用指南
    SqlHelper中使用事务
    QQ 影音,功能手札
    Access 2007数据库压缩和修复数据库功能
    dhl:PetShop里面的sqlHelper相关操作
    dhl:svn客户端学习TortoiseSVN的基本使用方法
    从 if else 到设计模式的转变
  • 原文地址:https://www.cnblogs.com/qiufeihai/p/2430621.html
Copyright © 2011-2022 走看看