• <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 閱讀(95) 評論(0)  編輯 收藏 引用
            久久婷婷综合中文字幕| 久久香蕉超碰97国产精品| 国产高潮国产高潮久久久| 国产精品乱码久久久久久软件| 久久久久四虎国产精品| 国产精品99久久免费观看| 久久天天躁狠狠躁夜夜96流白浆 | 日韩AV无码久久一区二区| 国产999精品久久久久久| 久久综合丝袜日本网| 国产欧美一区二区久久| 久久99毛片免费观看不卡| 97久久综合精品久久久综合| 99久久99这里只有免费的精品| 久久久久亚洲av综合波多野结衣| 久久受www免费人成_看片中文| 久久久久久久91精品免费观看| 亚洲中文字幕久久精品无码APP | 看久久久久久a级毛片| 久久婷婷激情综合色综合俺也去| 久久99精品久久久久久hb无码| 国产精品99久久久久久人| 国产成人精品久久| 日韩AV毛片精品久久久| 久久久久久久久久久| 久久777国产线看观看精品| 久久国产精品国语对白| 久久中文字幕精品| 久久精品国产亚洲一区二区| 久久精品国产第一区二区| 一日本道伊人久久综合影| 99久久久国产精品免费无卡顿| 久久se精品一区精品二区国产| 香蕉99久久国产综合精品宅男自 | 国内精品久久人妻互换| 久久高清一级毛片| 7777久久亚洲中文字幕| 亚洲午夜无码AV毛片久久| 91视频国产91久久久| 99久久做夜夜爱天天做精品| 久久被窝电影亚洲爽爽爽|