zoukankan      html  css  js  c++  java
  • poj 1562 Oil Deposits (dfs)

    http://poj.org/problem?id=1562

    水题。

    code:

    #include<cstdio>
    #include<cstring>
    int tur[8][2] = {-1, -1, -10, -111, -11011010, -1} ;
    char map[101][101] ;
    int n, m, ans, num ;
    bool vis[101][101] ;
    struct node{
        int x, y ;
    }coor[10005] ;
    bool inmap(node p){
        if(p.x>=0&&p.x<n&&p.y>=0&&p.y<m)    return true ;
        return false ;
    }
    void bfs(int x, int y){
        node q[10005] ;
        vis[x][y] = false ;
        ans ++ ;
        int h = 0 ;
        int e = 0 ;
        q[e].x = x ;
        q[e++].y = y ;
        while(h<e){
            node p = q[h++] ;
            for(int i=0; i<8; i++){
                node temp ;
                temp.x = p.x + tur[i][0] ;
                temp.y = p.y + tur[i][1] ;
                if(inmap(temp))
                    if(vis[temp.x][temp.y]){
                        q[e++] = temp ;
                        vis[temp.x][temp.y] = false ;
                    }
            }
        }
    }
    int main(){
        int i, j ;
        while(~scanf("%d%d", &n, &m)&&n+m){
            num = 0 ;
            memset(vis, falsesizeof(vis)) ;
            for(i=0; i<n; i++){
                getchar() ;
                scanf("%s", map[i]) ;
                for(j=0; j<m; j++){
                    if(map[i][j]=='@'){
                        coor[num].x = i ;
                        coor[num++].y = j ;
                        vis[i][j] = true ;
                    }
                }
            }
            ans = 0 ;
            for(i=0; i<num; i++){
                if(vis[coor[i].x][coor[i].y])
                    bfs(coor[i].x, coor[i].y) ;
            }
            printf("%d\n", ans) ;
        }
        return 0 ;} 
  • 相关阅读:
    在VMware9.0上安装CentOS6.3+mysql5.5.28数据库 东师理想
    Python学习总结(二)python的练习方法
    gdb调试nasm语法的汇编程序(转载)
    配置Bochs
    量变与质变(生活中,技术上)
    设置gdb反汇编语法为intel(转载)
    Python学习总结(一)
    2012暑假计划
    理解TCP为什么需要进行三次握手(白话)(转载)
    对自己的学习方式的思考(转载)
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2376097.html
Copyright © 2011-2022 走看看