• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ArcTan

            dfs
            隨筆 - 16, 文章 - 117, 評論 - 6, 引用 - 0
            數據加載中……

            poj3026(floodfill+prim)

            http://www.shnenglu.com/jh818012/articles/165674.html

            這個是我sb隊友寫的題解,一看就發現了錯誤,哈哈哈,不過AC了!!!!

            bfs+prim,我不懂floodfill,不過bfs還是懂的。今晚終于寫了個bfs了,AC真是爽啊。哈哈哈哈哈,
            悲催的數據的輸入,要注意注意呀,以后涉及字符串輸入的,都要小心哈!用gets()比較好哦啊

            #include<stdio.h>
            #include
            <string.h>
            #include
            <math.h>
            int x,y,tot;
            int    map[2505][2505],a[10005],b[10005],p[2505],que[1000005];
            int dis[2505],vis[2505];

            int bfs(int s)
            {
                
            int head,tail,i,x1,y1,now;
                memset(b,
            0,sizeof(b));

                que[
            1]=p[s];
                b[p[s]]
            =1;
                head
            =0;
                tail
            =1;
                
            while (head<tail)
                {
                    head
            ++;
                    now
            =que[head];
                    x1
            =(now-1)/y+1;
                    y1
            =(now-1)%y+1;

                    
            if (x1>1&&!b[now-y]&&a[now-y])
                    {
                        tail
            ++;
                        que[tail]
            =now-y;
                        b[now
            -y]=b[now]+1;
                    }
                    
            if (x1<x&&!b[now+y]&&a[now+y])
                    {
                        tail
            ++;
                        que[tail]
            =now+y;
                        b[now
            +y]=b[now]+1;
                    }
                    
            if (y1>1&&!b[now-1]&&a[now-1])
                    {
                        tail
            ++;
                        que[tail]
            =now-1;
                        b[now
            -1]=b[now]+1;
                    }
                    
            if (y1<y&&!b[now+1]&&a[now+1])
                    {
                        tail
            ++;
                        que[tail]
            =now+1;
                        b[now
            +1]=b[now]+1;
                    }
                }
                
            for (i=1; i<=tot ; i++ )
                    map[s][i]
            =b[p[i]]-1;
            }

            int prim()
            {
                
            int i,j,sum,min,minj;
                
            for (i=1; i<=tot ; i++ )
                {
                    dis[i]
            =100000000;
                    vis[i]
            =1;
                }
                sum
            =0;
                dis[
            1]=0;
                
            for (i=1; i<=tot ; i++ )
                {
                    min
            =100000000;
                    
            for (j=1; j<=tot ; j++ )
                        
            if (dis[j]<min&&vis[j])
                        {
                            min
            =dis[j];
                            minj
            =j;
                        }
                    sum
            +=min;
                    vis[minj]
            =0;
                    
            for (j=1; j<=tot ; j++ )
                        
            if (vis[j]&&map[minj][j]<dis[j])
                            dis[j]
            =map[minj][j];
                }
                
            return sum;
            }
            int init()
            {
                
            int i,j;
                
            char ch[55];
                scanf(
            "%d%d",&y,&x);
                    tot
            =0;
                    gets(ch);
                    
            for (i=1; i<=x ; i++ )
                    {
                        gets(ch);
                        
            for (j=1; j<=y ; j++ )
                        {
                            
            if (ch[j-1]=='#')
                                a[i
            *y-y+j]=0;
                            
            else if (ch[j-1]==' ')
                                a[i
            *y-y+j]=1;
                            
            else
                            {
                                tot
            ++;
                                p[tot]
            =i*y-y+j;
                                a[i
            *y-y+j]=1;
                            }
                        }
                    }
            }
            int work()
            {
                
            int i,ans;
                
            for (i=1; i<=tot ; i++ )
                    bfs(i);
                ans
            =prim();
                printf(
            "%d\n",ans);
            }
            int main()
            {
                
            int n;
                scanf(
            "%d",&n);
                
            while (n>0)
                {
                    n
            --;
                    init();
                    work();
                }
                
            return 0;
            }


            要開始注意代碼風格了,我的代碼太難看啦!!!

            posted on 2012-03-17 01:29 wangs 閱讀(242) 評論(0)  編輯 收藏 引用 所屬分類: ACM-201203

            久久成人影院精品777| 国产精品9999久久久久| 天堂无码久久综合东京热| 久久毛片一区二区| 国产成人精品白浆久久69| 精品久久久久一区二区三区| 亚洲精品无码久久毛片| 久久久久无码精品国产不卡| 国内精品伊人久久久久网站| 国产精品久久久香蕉| 久久综合给合久久狠狠狠97色69 | 欧美一级久久久久久久大片| 中文字幕精品久久久久人妻| 99热成人精品热久久669| 亚洲午夜无码久久久久小说| 国产产无码乱码精品久久鸭| 中文字幕亚洲综合久久菠萝蜜| 性欧美大战久久久久久久久| 青青热久久国产久精品| 9191精品国产免费久久| 久久精品一本到99热免费| 久久亚洲精品国产精品婷婷| 久久国产成人亚洲精品影院| 激情伊人五月天久久综合| 久久精品国产久精国产一老狼| 岛国搬运www久久| 久久本道伊人久久| 99久久精品午夜一区二区| 久久久久久无码Av成人影院| 少妇无套内谢久久久久| 国产精品久久久久久久久久影院 | 久久久久亚洲AV无码去区首| 久久青草国产精品一区| 国产精品久久久久影院嫩草| 日韩人妻无码精品久久久不卡| 中文无码久久精品| 乱亲女H秽乱长久久久| 日产精品久久久久久久| 热re99久久6国产精品免费| 欧美va久久久噜噜噜久久| 国产精品久久亚洲不卡动漫|