• <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)  編輯 收藏 引用
            国产精品一区二区久久精品涩爱| 久久久久亚洲爆乳少妇无| 久久国产热这里只有精品| 国产精品久久久久影院色| 久久久久久精品免费看SSS| 一本久久精品一区二区| 亚洲国产成人久久一区久久| 国产精品九九九久久九九| 国产三级久久久精品麻豆三级 | 久久久久久av无码免费看大片| 93精91精品国产综合久久香蕉| 国产91久久综合| 亚洲国产一成久久精品国产成人综合 | 久久久久综合国产欧美一区二区| 久久精品夜色噜噜亚洲A∨ | 久久影视国产亚洲| 日本人妻丰满熟妇久久久久久| 久久精品国产久精国产思思| 亚洲精品美女久久久久99| 国产欧美久久久精品| 久久这里只有精品视频99| 亚洲综合伊人久久综合| 久久九九青青国产精品| 久久久久久午夜精品| 国产一区二区精品久久| 午夜福利91久久福利| 国产精品久久久久久久| 久久男人中文字幕资源站| 色婷婷久久综合中文久久蜜桃av| 中文字幕成人精品久久不卡 | 久久久久久精品成人免费图片| 久久人人妻人人爽人人爽| 国产99久久九九精品无码| 国内精品人妻无码久久久影院导航| 青青草国产成人久久91网| 精品国产乱码久久久久久人妻| 国产毛片久久久久久国产毛片 | 国产精品久久久久久久午夜片| 色88久久久久高潮综合影院| 老司机国内精品久久久久| 亚洲精品美女久久777777|