• <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>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0
            我的第一次……
            第一次使用九維數(shù)組……
            簡單地BFS即可。
            以下是我的代碼:
            #include<stdio.h>
            #include
            <string.h>
            #define max_size 300000
            const long change[  ][9]={{1,1,0,1,1,0,0,0,0},
                                      {
            1,1,1,0,0,0,0,0,0},
                                      {
            0,1,1,0,1,1,0,0,0},
                                      {
            1,0,0,1,0,0,1,0,0},
                                      {
            0,1,0,1,1,1,0,1,0},
                                      {
            0,0,1,0,0,1,0,0,1},
                                      {
            0,0,0,1,1,0,1,1,0},
                                      {
            0,0,0,0,0,0,1,1,1},
                                      {
            0,0,0,0,1,1,0,1,1}};
            struct
            {
                
            long count,front,rear,item[max_size][9];
            }q;
            void Clear()
            {
                q.count
            =0;q.front=0;q.rear=-1;
            }
            void Push(long *x)
            {
                q.count
            ++;
                q.rear
            ++;
                
            for(long i=0;i<9;i++)
                  q.item[q.rear][i]
            =x[i];
            }
            void Pop(long *x)
            {
                q.count
            --;
                
            for(long i=0;i<9;i++)
                  x[i]
            =q.item[q.front][i];
                q.front
            ++;
            }
            bool Empty()
            {
                
            return (q.count==0);
            }

            int d[4][4][4][4][4][4][4][4][4];
            int f[4][4][4][4][4][4][4][4][4];
            long r[17];

            void init()
            {
                
            for(long i=0;i<9;i++) scanf("%ld",&r[i]);
                memset(d,
            -1,sizeof(d));
                memset(f,
            -1,sizeof(f));
            }
            bool ok(long *x)
            {
                
            for(long i=0;i<9;i++)
                  
            if(x[i]) return false;
                
            return true;
            }
            void bfs()
            {
                
            long t[17],s[17];
                Clear();
                d[r[
            0]][r[1]][r[2]][r[3]][r[4]][r[5]][r[6]][r[7]][r[8]]=0;
                Push(r);
                
            while(!Empty())
                {
                   Pop(t);
                   
            if(ok(t)) break;
                   
                   
            for(long i=0;i<9;i++)
                   {
                      
            for(long j=0;j<9;j++) s[j]=(t[j]+change[i][j])%4;
                      
            if(d[s[0]][s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]]==-1)
                      {
                         d[s[
            0]][s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]]=d[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]][t[6]][t[7]][t[8]]+1;
                         f[s[
            0]][s[1]][s[2]][s[3]][s[4]][s[5]][s[6]][s[7]][s[8]]=i;
                         Push(s);
                      }
                   }
                }
            }
            void output()
            {
                
            long t[17],ans[30],tot,tmp;
                
            for(long i=0;i<9;i++) t[i]=0;
                tot
            =0;
                
            while(f[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]][t[6]][t[7]][t[8]]!=-1)
                {
                   tot
            ++;
                   tmp
            =f[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]][t[6]][t[7]][t[8]];
                   ans[tot]
            =tmp+1;
                   
            for(long i=0;i<9;i++)
                     
            if(change[tmp][i])
                       t[i]
            =(t[i]+3)%4;
                }
                
            bool first=true;
                
            for(long i=tot;i>=1;i--)
                {
                   
            if(first) first=false;
                   
            else printf(" ");
                   printf(
            "%ld",ans[i]);
                }
                printf(
            "\n");
            }
            int main()
            {
                init();
                bfs();
                output();
            return 0;
            }


            posted on 2010-04-07 21:47 lee1r 閱讀(358) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:搜索
            国产91久久精品一区二区| 亚洲精品国精品久久99热| 久久婷婷五月综合成人D啪 | AV无码久久久久不卡蜜桃| 伊人久久亚洲综合影院| 久久国产精品无| 久久亚洲精品国产精品婷婷| 天天综合久久一二三区| 亚洲伊人久久成综合人影院 | 久久本道久久综合伊人| 久久91这里精品国产2020| 久久国产视频99电影| 亚洲天堂久久久| 亚洲国产精品高清久久久| 久久久精品国产sm调教网站| 久久久久女人精品毛片| 久久久久久久综合日本亚洲| 精品国产热久久久福利| 久久这里的只有是精品23| 久久久噜噜噜www成人网| 精品久久久久久久久中文字幕| 久久亚洲国产中v天仙www| 久久久久国产精品嫩草影院 | 亚洲国产天堂久久综合网站| 91亚洲国产成人久久精品| 中文成人久久久久影院免费观看| 狠狠精品久久久无码中文字幕| 精品国产乱码久久久久久1区2区| 日韩精品久久久久久| 久久精品中文字幕一区| 久久精品国产精品青草| 欧美日韩精品久久久免费观看| 香蕉久久av一区二区三区| 久久艹国产| 久久国产亚洲精品无码| 一级a性色生活片久久无| 精品国产福利久久久| 亚洲伊人久久精品影院| 久久无码人妻精品一区二区三区| 久久棈精品久久久久久噜噜| 久久久久国产一区二区三区|