• <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 
            <queue>
            #include 
            <string>
            using namespace std;

            int r, c;

            char  map[1001][1001];
            bool  hash[1001][1001];
            int   tu[1001][1001];

            void read()
            {
                scanf(
            "%d %d"&r, &c);
                getchar();
                
            for(int i = 0; i < r; i ++) gets(map[i]);
            }

            struct nod
            {
                
            int x, y;
            };

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

            queue 
            <nod> q;

            bool check(nod st)
            {
                
            if(st.x < 0 || st.y < 0 || st.x >=|| st.y >= c)
                    
            return false;
                
            if(map[st.x][st.y] == '#' || map[st.x][st.y] == 'J'return false;
                
            return true;
            }

            void bfs()
            {
                
            int i, j, step = 0, size;
                nod temp, t;
                
            while(!q.empty())
                {
                    size 
            = q.size();
                    
            while(size --)
                    {
                        temp 
            = q.front();
                        q.pop();
                        
            for(i = 0; i < 4; i ++)
                        {
                            t.x 
            = temp.x + move[i][0];
                            t.y 
            = temp.y + move[i][1];     
                            
            if(tu[t.x][t.y] > step + 1 && check(t))
                            {
                                tu[t.x][t.y] 
            = step + 1;
                                q.push(t);
                            }
                        }   
                    }
                    step 
            ++;
                }
            }

            bool final(nod sta)
            {
                
            if(sta.x < 0 || sta.y < 0 || sta.x >= r || sta.y >= c)
                    
            return true;
                
            return false;
            }

            bool ok(nod sta, int step)
            {
                
            if(map[sta.x][sta.y] == '#' || tu[sta.x][sta.y] <= step + 1 || hash[sta.x][sta.y])
                    
            return false;
                
            return true;
            }

            bool expend(nod sta, int step)
            {
                nod t;
                
            for(int i = 0; i < 4; i ++)
                {
                    t.x 
            = sta.x + move[i][0];
                    t.y 
            = sta.y + move[i][1];
                    
            if(final(t))       return true;
                    
            if(ok(t, step))    
                    {
                        hash[t.x][t.y] 
            = 1;
                        q.push(t);
                    }
                }
                
            return false;
            }

            int bfs_person(int x, int y)
            {
                
            int i, j, step = 0, size;
                
            while(!q.empty()) q.pop();
                nod temp, t;
                temp.x 
            = x;
                temp.y 
            = y;
                q.push(temp);
                
            while(!q.empty())
                {
                    size 
            = q.size();
                    
            while(size --)
                    {
                        temp 
            = q.front();
                        q.pop();
                        
            if(expend(temp, step)) return step + 1;
                    }
                    step 
            ++;
                }
                
            return -1;
            }

            void solve()
            {
                
            int i, j, x, y;
                nod tp;
                
            for(i = 0; i < r; i ++)
                
            for(j = 0; j < c; j ++)
                    tu[i][j] 
            = 999999;
                
            while(!q.empty()) q.pop();
                
            for(i = 0; i < r; i ++)
                
            for(j = 0; j < c; j ++)
                {
                    
            if(map[i][j] == 'F')
                    {
                        tp.x 
            = i;    tp.y = j;
                        tu[i][j] 
            = 0;
                        q.push(tp);
                    }
                    
            if(map[i][j] == 'J')
                    {
                        x 
            = i;
                        y 
            = j;
                    }
                }
                bfs();
                
                
            int ans = bfs_person(x, y);
                
            if(ans < 0) puts("IMPOSSIBLE");
                
            else        printf("%d\n",ans);
                
            }

            int main()
            {
                read();
                solve();
            }

            posted on 2009-08-28 20:26 superlong 閱讀(95) 評論(0)  編輯 收藏 引用
            avtt天堂网久久精品| 亚洲伊人久久大香线蕉综合图片| 欧美一区二区三区久久综| 久久亚洲私人国产精品| 亚洲天堂久久精品| 久久笫一福利免费导航| 综合网日日天干夜夜久久| 青草影院天堂男人久久| 久久久久久久综合狠狠综合| 97久久久久人妻精品专区| 久久国产成人午夜aⅴ影院| 人妻无码中文久久久久专区| 青青青伊人色综合久久| 中文字幕久久波多野结衣av| 99精品久久久久久久婷婷| 久久AV高潮AV无码AV| 久久se精品一区精品二区国产| 欧美亚洲色综久久精品国产| 久久婷婷人人澡人人| 国产精品久久免费| 人妻无码αv中文字幕久久| 久久人搡人人玩人妻精品首页| 久久香蕉国产线看观看99| 久久精品国产亚洲AV嫖农村妇女| 久久强奷乱码老熟女| 亚洲欧美日韩精品久久| 国产一级持黄大片99久久| 亚洲精品国精品久久99热一| 怡红院日本一道日本久久 | 国产精品久久久99| 人妻丰满AV无码久久不卡| 国产精品亚洲综合久久| 久久久免费观成人影院 | 国内精品久久久久久久久电影网| 久久棈精品久久久久久噜噜| 久久精品国产清自在天天线| 亚洲精品国精品久久99热| 久久久精品国产| 亚洲va久久久噜噜噜久久狠狠| 亚洲va久久久噜噜噜久久天堂 | 欧美久久精品一级c片片|