• <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 閱讀(97) 評論(0)  編輯 收藏 引用
            亚洲国产精品综合久久网络| 久久久久免费精品国产| 97久久超碰国产精品旧版| 午夜久久久久久禁播电影| 久久久久久久久无码精品亚洲日韩 | 伊人久久精品线影院| 久久国产精品免费一区二区三区| 亚洲欧美久久久久9999| 97精品国产97久久久久久免费| 狠狠色婷婷综合天天久久丁香| 久久996热精品xxxx| 亚洲成色WWW久久网站| 国产午夜福利精品久久| 性做久久久久久久| 午夜精品久久久久久影视riav| 国产美女久久久| 天天躁日日躁狠狠久久| 久久亚洲国产成人精品无码区| 久久精品中文闷骚内射| 久久久国产精华液| 蜜臀久久99精品久久久久久| 久久久精品午夜免费不卡| 精品久久久中文字幕人妻| 欧美精品福利视频一区二区三区久久久精品| 一本色综合网久久| 亚洲日本va午夜中文字幕久久| 91亚洲国产成人久久精品| 久久国产乱子伦免费精品| 伊人久久综合成人网| 久久国产欧美日韩精品| 婷婷久久综合九色综合九七| 国产呻吟久久久久久久92| 久久er国产精品免费观看8| 久久中文字幕一区二区| 欧美777精品久久久久网| 嫩草影院久久99| 久久精品国产精品亜洲毛片| 国内精品久久久久久久久| 亚洲国产天堂久久综合网站| 国产精品永久久久久久久久久| 国产精品一区二区久久精品无码 |