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 ;} 
  • 相关阅读:
    3D Bezier Curve, Matlab Code
    Matlab Bezier
    python与matlab混合编程
    Matlab P文件——加快Matlab程序,保护你的算法(z)
    Simens NX (原UG)内部代码逆向分析 / Inner code Reverse analysis of NX software
    Matlab扩展编程
    《数值分析及其MATLAB实现》(任玉杰)扫描版[PDF]
    NURBS Toolbox by D.M. Spink (matlab)
    贝塞尔曲线
    BSpline & NURBS (Matlab Code)
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2376097.html
Copyright © 2011-2022 走看看