• <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
            數據加載中……

            poj3414(bfs)

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

            bfs:都是些基本的算法了,各種bfs寫了不少啦。
            這個題目也挺簡單的,主要是那幾個轉移方向還是要優化下好寫,覺得自己寫得還可以哈:
            嘿嘿:
            bfs:0ms
            #include<stdio.h>
            #include
            <string.h>
            #include
            <math.h>
            int a[2],c,head,tail;
            int que[10005][2],pre[10005],p[10005],vis[105][105],ans[10005];
            int check()
            {
                
            if (que[tail][0]==c||que[tail][1]==c)
                    
            return 1;
                
            return 0;
            }
            int Fill(int i)
            {
                
            int t=tail+1;
                que[t][
            0]=que[head][0];
                que[t][
            1]=que[head][1];
                que[t][i
            -1]=a[i-1];
                
            if (!vis[que[t][0]][que[t][1]])
                {
                    vis[que[t][
            0]][que[t][1]]=1;
                    p[t]
            =i;
                    pre[t]
            =head;
                    
            return 1;
                }
                
            return 0;
            }
            int Drop(int i)
            {
                
            int t=tail+1;
                que[t][
            0]=que[head][0];
                que[t][
            1]=que[head][1];
                que[t][i
            -1]=0;
                
            if (!vis[que[t][0]][que[t][1]])
                {
                    vis[que[t][
            0]][que[t][1]]=1;
                    p[t]
            =2+i;
                    pre[t]
            =head;
                    
            return 1;
                }
                
            return 0;
            }
            int Four(int i,int j)
            {
                
            int min,t=tail+1;
                min
            =(que[head][i-1])<(a[j-1]-que[head][j-1])?(que[head][i-1]):(a[j-1]-que[head][j-1]);
                que[t][j
            -1]=que[head][j-1]+min;
                que[t][i
            -1]=que[head][i-1]-min;
                
            if (!vis[que[t][0]][que[t][1]])
                {
                    vis[que[t][
            0]][que[t][1]]=1;
                    p[t]
            =4+i;
                    pre[t]
            =head;
                    
            return 1;
                }
                
            return 0;
            }
            int bfs()
            {
                
            int i,tmp;
                memset(vis,
            0,sizeof(vis));
                head
            =0;
                tail
            =1;
                que[
            1][0]=0;
                que[
            1][1]=0;
                vis[
            0][0]=1;
                pre[
            1]=0;
                p[
            1]=0;
                
            while (head<tail)
                {
                    head
            ++;
                    tmp
            =1;
                    
            for (i=1; i<=2 ; i++ )
                    {
                        
            if (Fill(i))
                            tail
            ++;
                        
            if (check())
                            
            return tail;
                        
            if (Drop(i))
                            tail
            ++;
                        
            if (check())
                            
            return tail;
                        
            if (Four(i,i+tmp))
                            tail
            ++;
                        
            if (check())
                            
            return tail;
                        tmp
            =-1;
                    }
                }
                
            return 0;
            }
            int print(int k)
            {
                
            int i;
                
            if (!k)
                {
                    printf(
            "impossible\n");
                    
            return 0;
                }
                i
            =0;
                
            while (k)
                {
                    ans[
            ++i]=p[k];
                    k
            =pre[k];
                }
                printf(
            "%d\n",i-1);
                
            for (k=i-1; k>=1 ; k-- )
                {
                    
            if (ans[k]<=2)
                    {
                        printf(
            "FILL(%d)\n",ans[k]);
                        
            continue;
                    }
                    
            if (ans[k]<=4)
                    {
                        printf(
            "DROP(%d)\n",ans[k]-2);
                        
            continue;
                    }
                    
            if (ans[k]==5)
                        printf(
            "POUR(1,2)\n");
                    
            else
                        printf(
            "POUR(2,1)\n");
                }
                
            return 0;
            }

            int main()
            {
                
            int k;
                scanf(
            "%d%d%d",&a[0],&a[1],&c);
                
            if (c>a[0]&&c>a[1])
                    k
            =0;
                
            else
                    k
            =bfs();
                print(k);
                
            return 0;
            }

            這幾天的bfs,dfs,都是第一次就AV,挺爽的,嘿嘿。
            多寫寫惡心的代碼,以后就不惡心了,哈哈。

            很納悶,那些用很少內存的是怎么做到的呢?看來自己還是很弱啊~~~

            posted on 2012-04-02 17:47 wangs 閱讀(811) 評論(0)  編輯 收藏 引用 所屬分類: ACM-模擬

            亚洲国产成人久久综合区| 久久久中文字幕日本| 婷婷综合久久中文字幕蜜桃三电影 | 久久久久久亚洲精品不卡| 久久久婷婷五月亚洲97号色 | 尹人香蕉久久99天天拍| 亚洲七七久久精品中文国产| 99久久国产热无码精品免费久久久久 | 精品国产91久久久久久久a| 麻豆精品久久久久久久99蜜桃| 亚洲国产另类久久久精品小说| 久久最新精品国产| 久久精品免费一区二区| 99久久99久久精品国产片| 99久久夜色精品国产网站| 丁香久久婷婷国产午夜视频| 久久亚洲私人国产精品| 久久综合视频网站| 亚洲嫩草影院久久精品| 少妇久久久久久久久久| 国内精品久久国产| 久久精品无码一区二区日韩AV| 久久久久亚洲av无码专区喷水| 亚洲国产精品成人久久蜜臀| 久久综合丁香激情久久| 久久亚洲精品中文字幕| 97精品依人久久久大香线蕉97| 久久久久久极精品久久久| 久久久久国产一级毛片高清版| 久久婷婷五月综合色高清| 色老头网站久久网| 亚洲国产日韩欧美综合久久| 久久伊人中文无码| 94久久国产乱子伦精品免费| 韩国三级大全久久网站| www.久久热| 久久99国产精品99久久| 91精品国产高清久久久久久国产嫩草 | 久久精品国产亚洲AV香蕉| 久久午夜无码鲁丝片秋霞| 久久人人爽人人人人片av|