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

            閱讀排行榜

            評論排行榜

            第一個雙廣
            #include <iostream>
            #include 
            <string>
            #include 
            <queue>
            #include 
            <map>
            using namespace std;

            char change[][10= {"413526789""253146789""152463789""136425789"
                                 
            "123746859""123586479""123485796""123469758"};
            char end[11];
            string sta;
            int num;
            bool flag = 0;

            queue 
            < string > q[2]; // 0 -> zheng  1-> fan
            map <string , bool> h[2];

            void expend(int type, string ini)
            {
                
            char next[10];
                
            forint i= 0; i< 8; i ++ )
                {
                    
            forint j= 0; j< 9; j ++ )
                        next[j]
            = ini[ change[i][j]- '0'- 1 ];
                    next[
            9]= 0;
                    
            if( h[type][next] ) continue;
                    
            if( h[1-type][next] ) 
                    {
                        flag 
            = 1;
                        
            return;
                    }
                    q[type].push(next);
                    h[type][next] 
            = 1;
                }
            }

            int bfs()
            {
                
            int cnt = 0, index, len;
                
            while!q[0].empty() ) q[0].pop();
                
            while!q[1].empty() ) q[1].pop();
                h[
            0].clear();    h[1].clear();
                sta 
            = "123456789";
                h[
            0][sta] = 1;
                h[
            1][end] = 1;
                
            if(h[0][end]) return 0;
                q[
            0].push(sta);
                q[
            1].push(end);
                flag 
            = 0;
                
            string temp;
                
            while!q[0].empty() || !q[1].empty() )
                {
                    index 
            = 0;
                    
            if( q[0].size() > q[1].size() ) index = 1;
                    
            if( q[index].size() == 0 ) index = 1 - index;
                    len 
            = q[index].size();    
                    
            while(len --)
                    {
                        temp 
            = q[index].front();
                        q[index].pop();
                        expend(index, temp);
                        
            if(flag) break;
                    }
                    cnt 
            ++;
                    
            if(flag) return cnt;
                    
            if(cnt > num) return -1;
                }
            }


            int main()
            {
                
            int test = 0;
                
            while(gets(end) != NULL)
                {
                    
            if!strcmp(end, "0000000000") ) break;
                    num 
            = end[0- '0';
                    
            for(int i = 0; i <= 9; i ++) end[i] = end[i + 1];
                    
            int ans = bfs();
                    
            if(ans < 0 || (ans >0 && num < ans) ) ans = -1;
                    printf(
            "%d. %d\n"++test, ans);
                }
            }

            如果使用逆序判重的話當然會跑得更快
            #include <iostream>
            #include 
            <string>
            #include 
            <queue>
            using namespace std;

            char change[][10= {"413526789""253146789""152463789""136425789"
                                 
            "123746859""123586479""123485796""123469758"};
            char end[11];
            string sta;
            int num;
            bool flag = 0;

            queue 
            < string > q[2]; // 0 -> zheng  1-> fan
            bool h[2][370000];

            int map(string ss)
            {
                
            int hash = 0base = 1, answer = 0;
                
            for(int i = 0; i < 9; i ++)
                {
                    
            if(!basebase = 1;
                    
            base *= i; hash = 0;
                    
            for(int j = 0; j < i; j ++)
                    
            if(ss[j] > ss[i]) hash ++;
                    answer 
            += hash * base;
                }
                
            return answer;
            }

            void expend(int type, string ini)
            {
                
            char next[10];
                
            int tmp;
                
            forint i= 0; i< 8; i ++ )
                {
                    
            forint j= 0; j< 9; j ++ )
                        next[j]
            = ini[ change[i][j]- '0'- 1 ];
                    next[
            9]= 0;
                    tmp 
            = map(next);
                    
            if( h[type][tmp] ) continue;
                    
            if( h[1-type][tmp] ) 
                    {
                        flag 
            = 1;
                        
            return;
                    }
                    q[type].push(next);
                    h[type][tmp] 
            = 1;
                }
            }

            int bfs()
            {
                
            int cnt = 0, index, len;
                
            while!q[0].empty() ) q[0].pop();
                
            while!q[1].empty() ) q[1].pop();
                memset(h, 
            0sizeof(h));
                sta 
            = "123456789";
                h[
            0][map(sta)] = 1;
                h[
            1][map(end)] = 1;
                
            if(h[0][map(end)]) return 0;
                q[
            0].push(sta);
                q[
            1].push(end);
                flag 
            = 0;
                
            string temp;
                
            while!q[0].empty() || !q[1].empty() )
                {
                    index 
            = 0;
                    
            if( q[0].size() > q[1].size() ) index = 1;
                    
            if( q[index].size() == 0 ) index = 1 - index;
                    len 
            = q[index].size();    
                    
            while(len --)
                    {
                        temp 
            = q[index].front();
                        q[index].pop();
                        expend(index, temp);
                        
            if(flag) break;
                    }
                    cnt 
            ++;
                    
            if(flag) return cnt;
                    
            if(cnt > num) return -1;
                }
            }

            int main()
            {
                
            int test = 0;
                
            while(gets(end) != NULL)
                {
                    
            if!strcmp(end, "0000000000") ) break;
                    num 
            = end[0- '0';
                    
            for(int i = 0; i <= 9; i ++) end[i] = end[i + 1];
                    
            int ans = bfs();
                    
            if(ans < 0 || (ans >0 && num < ans) ) ans = -1;
                    printf(
            "%d. %d\n"++test, ans);
                }
            }

            posted on 2009-08-21 20:34 superlong 閱讀(132) 評論(0)  編輯 收藏 引用
            午夜精品久久影院蜜桃| 精品熟女少妇a∨免费久久| 久久综合久久综合九色| 国产精品欧美亚洲韩国日本久久 | 久久亚洲综合色一区二区三区| 国产三级久久久精品麻豆三级| 国产成人香蕉久久久久| 精品综合久久久久久97| 久久A级毛片免费观看| 久久久精品日本一区二区三区| 亚洲AV无码1区2区久久| 精品久久国产一区二区三区香蕉| 日日狠狠久久偷偷色综合96蜜桃| 婷婷伊人久久大香线蕉AV| 久久久久久av无码免费看大片| 久久无码人妻一区二区三区| 久久亚洲国产成人影院网站| 久久99久久99精品免视看动漫| 久久这里有精品| 久久久久无码精品| 国产亚洲色婷婷久久99精品91| 欧美大香线蕉线伊人久久| 日韩欧美亚洲综合久久 | 婷婷综合久久中文字幕蜜桃三电影| 国产2021久久精品| 久久青青草原综合伊人| 国内精品久久久人妻中文字幕| 欧美亚洲国产精品久久| 久久天天躁狠狠躁夜夜2020| 天天久久狠狠色综合| 国产成年无码久久久久毛片| 亚洲AV无码久久精品成人| 日本五月天婷久久网站| 久久久久久国产精品无码下载| 久久久久亚洲AV无码专区网站| 99久久精品国产毛片| 欧美久久综合性欧美| 中文字幕亚洲综合久久2| 国产福利电影一区二区三区久久老子无码午夜伦不| 18岁日韩内射颜射午夜久久成人| 热99RE久久精品这里都是精品免费|