• <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>

            學習心得(code)

            superlong@CoreCoder

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

            公告

            文字可能放在http://blog.csdn.net/superlong100,此處存放代碼

            常用鏈接

            留言簿(4)

            我參與的團隊

            搜索

            •  

            最新隨筆

            最新評論

            • 1.?re: Poj 1279
            • 對于一個凹多邊形用叉積計算面積 后能根據結果的正負來判斷給的點集的時針方向?
            • --bsshanghai
            • 2.?re: Poj 3691
            • 你寫的這個get_fail() 好像并是真正的get_fail,也是說fail指向的串并不是當前結點的子串。為什么要這樣弄呢?
            • --acmer1183
            • 3.?re: HDU2295[未登錄]
            • 這個是IDA* 也就是迭代加深@ylfdrib
            • --superlong
            • 4.?re: HDU2295
            • 評論內容較長,點擊標題查看
            • --ylfdrib
            • 5.?re: HOJ 11482
            • 呵呵..把代碼發在這里很不錯..以后我也試試...百度的編輯器太爛了....
            • --csuft1

            閱讀排行榜

            評論排行榜

            /*
            ID:superlo1
            LANG:C++
            TASK:clocks
            */


            #include 
            <stdio.h>
            #include 
            <string.h>

            int ini[9];
            int move[10][10= {{},
                {
            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}
                };

            inline 
            int calc(int num[])
            {
                
            int sum = 0base = 1;
                
            for(int i = 0; i <= 8; i ++)
                {
                    sum 
            += num[i]*base;
                    
            base *= 4;
                }
                
            return sum; 
            }

            inline 
            void decode(int state, int num[])
            {
                
            for(int i = 0; i < 9; i ++)
                {
                    num[i] 
            = state % 4;
                    state 
            /= 4;
                }
            }

            void read()
            {
                
            for(int i = 0; i < 9; i ++)
                {
                    scanf(
            "%d"&ini[i]);
                    ini[i] 
            = (ini[i] / 3% 4;
                }
                
            int num[9];
                decode(calc(ini), num);
                
            //for(int i = 0; i < 9; i ++) printf("%d ", num[i]);
                
            //puts("");
            }

            int  q[300000];
            int  way[300000];
            int  step[300000];
            bool h[300000];
            int close, open;

            bool ok(int s)
            {
                
            if(s == 0return true;
                
            return false;
            }

            void out()
            {
                
            int cnt = 0, ans[10000], state;
                state 
            = open;
                
            while(state > 0)
                {
                    ans[cnt
            ++= step[state];
                    state 
            = way[state];
                }
                printf(
            "%d", ans[cnt-1]);
                
            for(int i = cnt - 2; i >= 0; i --) printf(" %d", ans[i]);puts("");
            }

            bool expend(int state)
            {
                
            int num[9], nnum[9];
                decode(state, num);
                
            //system("pause");
                for(int i = 1; i <= 9; i ++)
                {
                    
            for(int j = 0; j < 9; j ++)
                        nnum[j] 
            = (num[j] + move[i][j]) % 4;
                    
                    
            //printf("%d:", i);
                    int nstate = calc(nnum);
                    
            if(h[nstate]) continue;
                    
            //for(int j = 0; j < 9; j ++) printf("%d ", nnum[j]); puts("");
                    h[nstate] = 1;
                    q[
            ++open] = nstate;
                    way[open] 
            = close;
                    step[open] 
            = i;
                    
            if(ok(nstate)) return 1;
                }
                
            return 0;
            }

            void bfs()
            {
                
            int num[9];
                close 
            = -1, open = 0;
                
            int temp = calc(ini);
            //    printf("%d\n", temp);
                memset(h,0,sizeof(h));
                q[
            0= temp;
                h[temp] 
            = 1;
                way[
            0= -1;
                
            while(close < open)
                {
                    
            int size = open - close;
                    
            //printf("%d:\n", step);
                    while(size --)
                    {
                        temp 
            = q[++close];
                        
            int num[9];
                        decode(temp, num);
                        
            //puts("flag");
                        
            //for(int j = 0; j < 9; j ++) printf("%d ", num[j]); puts(":");
                        if(expend(temp))
                        {
                            
            out();            
                            
            return;
                        }
                    }
                }
            }

            int main()
            {
                freopen(
            "clocks.in","r",stdin);
                freopen(
            "clocks.out","w",stdout);
                read();
                bfs();
                
            //while(1);
            }

            posted on 2009-10-15 20:05 superlong 閱讀(135) 評論(0)  編輯 收藏 引用 所屬分類: USACO
            精品久久久久一区二区三区 | 国产精品视频久久| 久久国产热精品波多野结衣AV| 亚洲AV无码1区2区久久| 国产精品无码久久久久久| 久久久久久久尹人综合网亚洲| 久久久久人妻精品一区二区三区 | 久久久无码人妻精品无码| 亚洲人成精品久久久久| 国产精品久久久亚洲| 丁香久久婷婷国产午夜视频| 香蕉久久夜色精品国产尤物 | 国产综合成人久久大片91| 一级做a爰片久久毛片看看| 天天爽天天狠久久久综合麻豆| 伊人色综合久久天天| 久久久久久久综合狠狠综合| 粉嫩小泬无遮挡久久久久久| 久久黄色视频| 国产精品99久久久久久人| 日本久久中文字幕| 曰曰摸天天摸人人看久久久| 久久久无码人妻精品无码| 久久精品女人天堂AV麻| 久久er99热精品一区二区| 亚洲国产成人久久综合野外| 青青热久久综合网伊人| 久久亚洲精品中文字幕| 无码任你躁久久久久久| 久久精品18| 久久免费小视频| 久久久久久国产精品无码超碰| 2021国产精品午夜久久| 久久99精品久久久久久水蜜桃 | 久久99精品久久久久久久不卡| 9久久9久久精品| 久久se这里只有精品| 青青久久精品国产免费看| 国产成人久久精品二区三区| 久久婷婷色综合一区二区| 久久亚洲精精品中文字幕|