• <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://m.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 閱讀(246) 評論(0)  編輯 收藏 引用 所屬分類: ACM-201203

            久久国产香蕉视频| av色综合久久天堂av色综合在| 久久青草国产手机看片福利盒子| 久久久久久a亚洲欧洲aⅴ| 三级韩国一区久久二区综合| 久久婷婷激情综合色综合俺也去| 99久久综合狠狠综合久久| 四虎亚洲国产成人久久精品| 精品久久久久久中文字幕人妻最新| 狠狠色综合网站久久久久久久| 亚洲狠狠婷婷综合久久久久| 狠狠色综合网站久久久久久久| 久久久久亚洲AV无码网站| 亚洲午夜精品久久久久久浪潮| 久久精品国产91久久麻豆自制 | 精品久久久无码中文字幕天天| 久久人与动人物a级毛片| 国产亚洲精久久久久久无码AV| 久久亚洲中文字幕精品有坂深雪 | 久久综合亚洲色HEZYO社区| 99久久成人国产精品免费| 久久精品中文字幕一区| 国产叼嘿久久精品久久| 91精品国产综合久久久久久| 综合网日日天干夜夜久久| 色狠狠久久综合网| 无码任你躁久久久久久老妇| 一本久久久久久久| 久久久久四虎国产精品| 国产情侣久久久久aⅴ免费| 亚洲国产精品久久电影欧美| 久久这里只有精品首页| 久久综合亚洲鲁鲁五月天| 精品久久久久久久国产潘金莲| 久久这里只有精品视频99| 久久久久国产一区二区| 久久精品一区二区三区中文字幕| 久久精品国产欧美日韩| 亚洲国产精品综合久久网络 | 久久久无码精品亚洲日韩蜜臀浪潮| 久久99国产精品久久99小说|