• <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>
            #define H 12
            using namespace std;

            int movem[8][2= {{-2,1}, {-1,2}, {1,2}, {2,1}, 
                              {
            2,-1}, {1,-2}, {-1,-2}, {-2,-1}};
            int move_m[8][2= {{-1,0}, {0,1}, {0,1}, {1,0}, {1,0}, {0,-1}, {0,-1}, {-1,0}};
            int move[4][2= {{01}, {0-1}, {10}, {-10}};
            bool h[150][150][150];
            char map[11][11];
            int  nn, mm;
            int  ci, cj, mi, mj, pi, pj, si, sj;

            struct node
            {
                
            int c, m, p, step;
            }que[
            1000001];

            int  open, close;
            int  c, m, p, ans;
            node t, next;

            int hash(int a,int b)
            {
            return a * H + b;}

            void read_map()
            {
                
            int i, j;
                getchar();
                
            for(i = 0; i < nn; i ++) gets(map[i]);
                ci 
            = cj = mi = mj = pi = pj = -1;
                
            for(i = 0; i < nn; i ++)
                
            for(j = 0; j < mm; j ++)
                {
                    
            if(map[i][j] == 'C')
                    {ci 
            = i; cj = j; map[i][j] = '.';}
                    
            if(map[i][j] == 'P')
                    {pi 
            = i; pj = j; map[i][j] = '.';}
                    
            if(map[i][j] == 'M')
                    {mi 
            = i; mj = j; map[i][j] = '.';}
                    
            if(map[i][j] == 'S')
                    {si 
            = i; sj = j;}
                }
            }

            bool check_c(node st, int x, int y)
            {
                
            if(x<0 || y<0 || x>=nn || y>=mm) return false;
                
            if(h[st.c][st.m][st.p]) return false;
                
            if(map[x][y] == 'D' || hash(x, y) == st.m || hash(x, y) == st.p) return false;
                
            return true;
            }

            bool isok(int x, int y)
            {
                
            if(x==si && y==sj) return true;
                
            return false;
            }

            void ex_c()
            {
                next 
            = t;    next.step ++;
                
            int x, y, tx, ty;
                x 
            = next.c / H;        y = next.c % H;
                
            for(int i = 0; i < 4; i ++)
                {
                    tx 
            = x + move[i][0];
                    ty 
            = y + move[i][1];
                    next.c 
            = hash(tx, ty);
                    
            while(check_c(next, tx, ty))
                    {
                        
            //printf("ju: %d %d -> %d %d %d\n",x, y, tx, ty, ans);
                        if(isok(tx, ty))
                        {
                            ans 
            = next.step;
                            
            return;
                        }
                        h[next.c][next.m][next.p] 
            = 1;
                        que[
            ++open] = next;
                        tx 
            += move[i][0];
                        ty 
            += move[i][1];
                        next.c 
            = hash(tx, ty);
                    }
                }
            }

            bool check_for_m(int x, int y, node st, int key)
            {
                
            int xx = x+move_m[key][0], yy = y+move_m[key][1];
                
            //撇馬腳 
                if(xx < 0 || yy < 0 || xx >= nn || yy >= mm) return false;
                
            if(map[xx][yy] == 'D' || hash(xx, yy) == st.c || hash(xx, yy) == st.p || hash(xx, yy) == hash(si, sj))
                    
            return false;
                xx 
            = st.m / H;
                yy 
            = st.m % H;
                
            if(xx < 0 || xx >= nn || yy < 0 || yy >= mm ) return false;
                
            if(st.m == st.c || st.m == st.p || map[xx][yy] == 'D' || h[st.c][st.m][st.p]) return false;
                
            return true;
            }

            void ex_m()
            {
                next 
            = t;    next.step ++;
                
            int x, y, tx, ty;
                x 
            = next.m / H;        y = next.m % H;
                
            for(int i = 0; i < 8; i ++)
                {
                    tx 
            = x + movem[i][0];    ty = y + movem[i][1];
                    next.m 
            = hash(tx, ty);
                    
            if(check_for_m(x, y, next, i))
                    {
                        
            //printf("ma: %d %d -> %d %d %d\n",x, y, tx, ty, ans);
                        if(isok(tx, ty))
                        {
                            ans 
            = next.step;
                            
            return;
                        }
                        h[next.c][next.m][next.p] 
            = 1;
                        que[
            ++open] = next;
                    }
                }
            }

            bool isok_p(node st)
            {
                
            int x, y, inc, cnt;
                x 
            = st.p / H;    y = st.p % H;
                
            if(x == si)
                {
                    cnt 
            = 0; inc = 1;
                    
            if(y > sj) inc = -1;
                    
            for(int j = y;; j += inc)
                    {
                        
            if(map[x][j] == 'D' || hash(x, j) == st.c || hash(x, j) == st.m)
                            cnt 
            ++;
                        
            if(j == sj) break;
                    }
                    
            if(cnt == 1return true;
                    
            return false;
                }
                
            if(y == sj)
                {
                    cnt 
            = 0; inc = 1;
                    
            if(x > si) inc = -1;
                    
            for(int i = x;; i += inc)
                    {
                        
            if(map[i][y] == 'D' || hash(i, y) == st.c || hash(i, y) == st.m)
                            cnt 
            ++;
                        
            if(i == si) break;
                    }
                    
            if(cnt == 1return true;
                    
            return false;
                }
                
            return false;
            }

            bool check_p(node st, int x, int y)
            {
                
            if(x<0 || y<0 || x>=nn || y>=mm) return false;
                
            if(h[st.c][st.m][st.p]) return false;
                
            if(map[x][y] == 'D' || hash(x, y)==st.m || hash(x, y)==st.c) return false;
                
            if(hash(x, y) == hash(si, sj)) return false;
                
            return true;
            }

            void ex_p()
            {
                next 
            = t; next.step ++;
                
            int x, y, tx, ty;
                x 
            = next.p / H;        y = next.p % H;
                
            if(isok_p(next))
                {
                    ans 
            = next.step;
                    
            return;
                }
                
            for(int i = 0; i < 4; i ++)
                {
                    tx 
            = x + move[i][0];
                    ty 
            = y + move[i][1];
                    next.p 
            = hash(tx, ty);
                    
            while(check_p(next, tx, ty))
                    {
                        
            //printf("ju: %d %d -> %d %d %d\n",x, y, tx, ty, ans);
                        h[next.c][next.m][next.p] = 1;
                        que[
            ++open] = next;
                        tx 
            += move[i][0];
                        ty 
            += move[i][1];
                        next.p 
            = hash(tx, ty);
                    }
                }
            }

            void bfs()
            {
                open 
            = 0; close = -1;
                c 
            = hash(ci, cj);    m = hash(mi, mj);    p = hash(pi, pj);
                memset(h,
            0,sizeof(h));
                h[c][m][p] 
            = 1;
                que[
            0].c = c;    que[0].m = m;    que[0].p = p;
                que[
            0].step = 0;
                
            while(close < open)
                {
                    t 
            = que[++close];
                    ex_c();    
            if(ans > 0return;
                    ex_m();    
            if(ans > 0return;
                    ex_p();    
            if(ans > 0return;
                }
            }

            int main()
            {
                
            //freopen("in.txt","r",stdin);
                while(scanf("%d %d"&nn, &mm) != EOF)
                {
                    ans 
            = 0;
                    read_map();
                    bfs();
                    
            if(ans > 0) printf("%d\n",ans);
                    
            else        puts("OH!That's impossible!");
                    puts(
            "");
                }
                
            //while(1);
            }


            posted on 2009-08-18 15:56 superlong 閱讀(94) 評論(0)  編輯 收藏 引用
            久久香蕉一级毛片| 久久伊人五月丁香狠狠色| 漂亮人妻被黑人久久精品| 久久偷看各类wc女厕嘘嘘| 91久久香蕉国产熟女线看| 亚洲国产精品无码久久久久久曰| 亚洲国产精品久久久天堂| 一本大道加勒比久久综合| 久久人人爽人人人人爽AV| 97久久精品无码一区二区| 国内精品久久久久久久亚洲 | 99久久免费国产特黄| 日本精品久久久中文字幕| 欧美亚洲国产精品久久久久| 免费观看久久精彩视频| 久久无码AV中文出轨人妻| 国产精品嫩草影院久久| 久久99亚洲网美利坚合众国| 麻豆精品久久久久久久99蜜桃| 狠狠色噜噜狠狠狠狠狠色综合久久| 久久亚洲精品国产亚洲老地址| 97久久国产亚洲精品超碰热| 精品久久久久久国产| 免费精品久久久久久中文字幕 | 亚洲国产成人久久综合碰| 国产一级持黄大片99久久| 婷婷久久久亚洲欧洲日产国码AV | 亚洲国产精品一区二区久久| AV无码久久久久不卡蜜桃| 久久久久国产视频电影| 久久91综合国产91久久精品| 日韩人妻无码精品久久免费一| 久久人人爽人人人人爽AV| 伊人久久大香线蕉综合热线| 青青草国产97免久久费观看| 国产成人无码精品久久久久免费 | 久久精品一区二区三区中文字幕| 97久久超碰成人精品网站| 97久久国产亚洲精品超碰热| 久久精品人人做人人爽97| 99国产欧美久久久精品蜜芽|