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

            學(xué)習(xí)心得(code)

            superlong@CoreCoder

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

            公告

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

            常用鏈接

            留言簿(4)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新隨筆

            最新評(píng)論

            • 1.?re: Poj 1279
            • 對(duì)于一個(gè)凹多邊形用叉積計(jì)算面積 后能根據(jù)結(jié)果的正負(fù)來(lái)判斷給的點(diǎn)集的時(shí)針?lè)较颍?
            • --bsshanghai
            • 2.?re: Poj 3691
            • 你寫(xiě)的這個(gè)get_fail() 好像并是真正的get_fail,也是說(shuō)fail指向的串并不是當(dāng)前結(jié)點(diǎn)的子串。為什么要這樣弄呢?
            • --acmer1183
            • 3.?re: HDU2295[未登錄](méi)
            • 這個(gè)是IDA* 也就是迭代加深@ylfdrib
            • --superlong
            • 4.?re: HDU2295
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --ylfdrib
            • 5.?re: HOJ 11482
            • 呵呵..把代碼發(fā)在這里很不錯(cuò)..以后我也試試...百度的編輯器太爛了....
            • --csuft1

            閱讀排行榜

            評(píng)論排行榜

            非常惡心的BFS
            #include <iostream>
            #include 
            <map>

            using namespace std;

            map 
            <string , int> h;

            int state_count;

            int move[4][2= {{-1 , 0},{1 , 0},{0 , -1},{0 , 1}};

            int  w, d, ii, ij;
            char a[31][31], ss[7], tt[7];
            bool jud[31][31][49][7];

            struct node
            {
                
            int x, y, s, c;
                
            char st[7];
            }que[
            1000001];

            char hash(char ch)
            {
                
            if(ch == 'r'return '1';
                
            if(ch == 'c'return '2';
                
            if(ch == 'g'return '3';
                
            if(ch == 'm'return '4';
                
            if(ch == 'b'return '5';
                
            if(ch == 'y'return '6';
                
            else          return '0';
            }

            void swap_flag(char ch[7])
            {
                h[ch] 
            = ++state_count;

                swap(ch[
            4], ch[5]); h[ch] = ++state_count; swap(ch[4], ch[5]);
                swap(ch[
            2], ch[3]); h[ch] = ++state_count; swap(ch[2], ch[3]);
                swap(ch[
            0], ch[1]); h[ch] = ++state_count; swap(ch[0], ch[1]);
                
                swap(ch[
            4], ch[5]); swap(ch[2], ch[3]);
                h[ch] 
            = ++state_count;
                swap(ch[
            4], ch[5]); swap(ch[2], ch[3]);

                swap(ch[
            4], ch[5]); swap(ch[0], ch[1]);
                h[ch] 
            = ++state_count;
                swap(ch[
            4], ch[5]); swap(ch[0], ch[1]);    
                
                swap(ch[
            0], ch[1]); swap(ch[2], ch[3]);
                h[ch] 
            = ++state_count;
                swap(ch[
            0], ch[1]); swap(ch[2], ch[3]);    
                
                swap(ch[
            0], ch[1]); swap(ch[2], ch[3]); swap(ch[4], ch[5]);
                h[ch] 
            = ++state_count;
                swap(ch[
            0], ch[1]); swap(ch[2], ch[3]); swap(ch[4], ch[5]);
            }

            void bulid_state()
            {
                
            char ch[7= "123456", temp;
                h.clear();
                state_count 
            = 0;
                
            int i, j, cnt = 1;
                swap_flag(ch);
                
            for(i = 2; i <= 6; i ++)
                {
                    
            if(cnt == 3 ) cnt = 1;
                    
            if(cnt == 1)
                    {
                        swap(ch[
            5], ch[3]); swap(ch[4], ch[2]);
                        swap_flag(ch);
                        cnt 
            ++;
                    }
                    
            else if(cnt == 2)
                    {
                        swap(ch[
            3], ch[1]); swap(ch[2], ch[0]);
                        swap_flag(ch);
                        cnt 
            ++;
                    }
                }
            }

            void find()
            {
                
            int i, j;
                
            for(i = 0; i < d; i ++)
                
            for(j = 0; j < w; j ++)
                
            if(a[i][j] == '#')
                {
                    ii 
            = i;
                    ij 
            = j;
                    a[i][j] 
            = 'w';
                    
            return;
                }
            }

            void changed(char ch[7], int i)
            {
                
            if(i == 0)
                {
                    tt[
            0= ch[3]; tt[1= ch[2]; tt[2= ch[0];
                    tt[
            3= ch[1]; tt[4= ch[4]; tt[5= ch[5];
                }
                
            if(i == 1)
                {
                    tt[
            0= ch[2]; tt[1= ch[3]; tt[2= ch[1];
                    tt[
            3= ch[0]; tt[4= ch[4]; tt[5= ch[5];
                }
                
            if(i == 2)
                {
                    tt[
            0= ch[4]; tt[1= ch[5]; tt[2= ch[2];
                    tt[
            3= ch[3]; tt[4= ch[1]; tt[5= ch[0];
                }
                
            if(i == 3)
                {
                    tt[
            0= ch[5]; tt[1= ch[4]; tt[2= ch[2];
                    tt[
            3= ch[3]; tt[4= ch[0]; tt[5= ch[1];
                }
                tt[
            6= '\0';
            }

            bool check(node t)
            {
                
            if(t.x < 0 || t.y < 0 || t.x >=|| t.y >= w || jud[t.x][t.y][h[t.st]][t.c] == 1 || a[t.x][t.y] == 'k')
                    
            return false;
                
            if(a[t.x][t.y] != 'w' && a[t.x][t.y] != 'k' && hash(a[t.x][t.y]) != t.st[0]) 
                    
            return false;
                
            if(a[t.x][t.y] != 'w' && a[t.x][t.y] != 'k' && hash(a[t.x][t.y]) == t.st[0&& t.st[0!= hash(ss[t.c]))
                    
            return false;
                
            return true;
            }

            int bfs()
            {
                
            int close = -1, open = 0, i, j;
                node tp, next;
                memset(jud, 
            0sizeof(jud));
                que[
            0].x = ii;
                que[
            0].y = ij;
                que[
            0].s = 0;
                que[
            0].c = 0;
                strcpy(que[
            0].st , "123456");

                jud[ii][ij][h[que[
            0].st]][0= 1;
                
                
            while(close < open)
                {
                    close 
            ++;
                    tp 
            = que[close];    
                    
            //printf("%d %d %s %d\n",tp.x,tp.y,tp.st,tp.c);
                    for(i = 0; i < 4; i ++)
                    {
                        next.x  
            = tp.x + move[i][0];
                        next.y  
            = tp.y + move[i][1];
                        next.s  
            = tp.s + 1;
                        next.c  
            = tp.c;
                        changed(tp.st , i);
                        strcpy( next.st , tt );
                        
            //printf("%d %d %s %s %d    %c\n",next.x,next.y,next.st,ss, next.c,a[next.x][next.y]);
                        if(check(next) == falsecontinue;
                            
                        
            if(hash(a[next.x][next.y]) == next.st[0&& next.st[0== hash(ss[next.c])) 
                            next.c 
            ++;
                        
            if(next.c == 6return next.s;
                        open 
            ++;
                        que[open] 
            = next;
                        jud[next.x][next.y][h[next.st]][next.c] 
            = 1;
                    }
                }
                
            return -1;
            }

            int main()
            {
                
            int step;
                
                bulid_state();
                
            while(scanf("%d %d",&w, &d), w+d)
                {
                    
            int i;
                    
            for(i = 0; i < d; i ++) scanf("%s",a[i]);
                    scanf(
            "%s",ss);
                    find();
                    step 
            = bfs();
                    
            if(step > 0) printf("%d\n", step);
                    
            else         puts("unreachable");
                }
                
            }
            /*
            7 4
            #ycbrkk
            kkkkgkk
            kkkkwkk
            kkkkmkk
            ycbrgm
            */



            posted on 2009-08-07 18:25 superlong 閱讀(370) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            午夜精品久久久久久毛片| 久久综合综合久久97色| 久久免费99精品国产自在现线| 国内精品久久久久久麻豆| 久久人妻少妇嫩草AV蜜桃| 国产美女亚洲精品久久久综合 | 久久er国产精品免费观看2| 久久精品国内一区二区三区| 久久久久无码专区亚洲av| 久久精品国产久精国产果冻传媒 | 亚洲欧美精品伊人久久| 久久综合久久性久99毛片| 国产亚洲精品美女久久久| 色欲综合久久躁天天躁| 久久精品人人做人人妻人人玩| 久久精品国产第一区二区| 久久国产高潮流白浆免费观看| 日韩电影久久久被窝网| 蜜臀久久99精品久久久久久小说 | 亚洲精品乱码久久久久久自慰| 久久亚洲精品视频| 亚洲精品乱码久久久久久按摩| 久久久久人妻一区精品| 精品久久久久久国产潘金莲| 久久精品青青草原伊人| 久久精品免费网站网| 秋霞久久国产精品电影院| 久久九九精品99国产精品| 久久久SS麻豆欧美国产日韩| 亚洲精品高清一二区久久| 久久er国产精品免费观看8| 香蕉久久夜色精品国产小说| 72种姿势欧美久久久久大黄蕉| 亚洲第一极品精品无码久久| 综合久久精品色| 国产精品中文久久久久久久| 一本综合久久国产二区| 亚洲欧洲精品成人久久曰影片| 久久精品一区二区三区中文字幕 | 久久精品国产免费| 99精品国产在热久久|