• <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>

            學(xué)習(xí)心得(code)

            superlong@CoreCoder

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

            公告

            文字可能放在http://blog.csdn.net/superlong100,此處存放代碼

            常用鏈接

            留言簿(4)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新隨筆

            最新評(píng)論

            • 1.?re: Poj 1279
            • 對(duì)于一個(gè)凹多邊形用叉積計(jì)算面積 后能根據(jù)結(jié)果的正負(fù)來(lái)判斷給的點(diǎn)集的時(shí)針?lè)较颍?
            • --bsshanghai
            • 2.?re: Poj 3691
            • 你寫(xiě)的這個(gè)get_fail() 好像并是真正的get_fail,也是說(shuō)fail指向的串并不是當(dāng)前結(jié)點(diǎn)的子串。為什么要這樣弄呢?
            • --acmer1183
            • 3.?re: HDU2295[未登錄](méi)
            • 這個(gè)是IDA* 也就是迭代加深@ylfdrib
            • --superlong
            • 4.?re: HDU2295
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --ylfdrib
            • 5.?re: HOJ 11482
            • 呵呵..把代碼發(fā)在這里很不錯(cuò)..以后我也試試...百度的編輯器太爛了....
            • --csuft1

            閱讀排行榜

            評(píng)論排行榜

            #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) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            久久99精品久久久大学生| 香港aa三级久久三级| 欧美国产精品久久高清| 日韩电影久久久被窝网| 久久人人添人人爽添人人片牛牛| 精品综合久久久久久98| 久久综合综合久久97色| 久久久久久亚洲精品影院| 色狠狠久久AV五月综合| 国产毛片久久久久久国产毛片| 久久久午夜精品| 久久亚洲精品中文字幕三区| 久久99精品国产麻豆宅宅| 婷婷综合久久中文字幕| 久久人人爽爽爽人久久久| 久久久久久噜噜精品免费直播 | 久久青青草原精品国产| 亚洲精品国产成人99久久| 久久人人爽人人爽人人片AV东京热| 狠狠色婷婷综合天天久久丁香| 婷婷久久综合九色综合九七| 伊人久久大香线蕉精品| 久久久久久久久无码精品亚洲日韩 | 国产成人久久精品二区三区| 日本人妻丰满熟妇久久久久久| 国内精品伊人久久久久网站| 国内精品久久久久伊人av| 精品久久久久久中文字幕大豆网| 精品国产乱码久久久久久浪潮| 成人国内精品久久久久一区| 国内高清久久久久久| 噜噜噜色噜噜噜久久| 精品久久久久久国产三级| 国产精品一区二区久久精品无码| 久久se精品一区二区| 久久99精品综合国产首页| 99999久久久久久亚洲| 精品久久久久久久久中文字幕| 久久不见久久见免费视频7| 精品乱码久久久久久久| 久久精品夜夜夜夜夜久久|