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 ;} 
  • 相关阅读:
    Linux系统负载
    full nat
    close wait 状态的随想
    记录一下 性能分析问题
    golang 反射
    socket里面那个又爱又恨的锁
    Difference between skbuff frags and frag_list
    浅析TCP协议---转载
    http 怎样关闭
    http 响应 ngx_http_send_header ngx_http_output_filter
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2376097.html
Copyright © 2011-2022 走看看