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

            O(1) 的小樂

            Job Hunting

            公告

            記錄我的生活和工作。。。
            <2011年1月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            統計

            • 隨筆 - 182
            • 文章 - 1
            • 評論 - 41
            • 引用 - 0

            留言簿(10)

            隨筆分類(70)

            隨筆檔案(182)

            文章檔案(1)

            如影隨形

            搜索

            •  

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            USACO 2.4 Overfencing

            /*
            ID: lvxiaol3
            LANG: C++
            TASK: maze1
            */
            #include<iostream>
            #include<fstream>
            #include<string.h>

            using namespace std;


            #define MAXWID 38
            #define MAXHT 100

            typedef struct Point Point;
            struct Point
            {
                int r, c;
            };

            int wid, ht;
            char maze[MAXHT*2+1][MAXWID*2+1+2];
            int dist[MAXHT*2+1][MAXWID*2+1];

            Point
            Pt(int r, int c)
            {
                Point p;

                p.r = r;
                p.c = c;
                return p;
            }

            typedef struct Queue Queue;
            struct Queue
            {
                Point p;
                int d;
            };

            Queue floodq[MAXHT*MAXWID];
            int bq, eq;

            /* if no wall between point p and point np, add np to queue with distance d+1 */
            void
            addqueue(int d, Point p, Point np)
            {
                if(maze[(p.r+np.r)/2][(p.c+np.c)/2] == ' ' && maze[np.r][np.c] == ' ')
                {
                    maze[np.r][np.c] = '*';
                    floodq[eq].p = np;
                    floodq[eq].d = d+1;
                    eq++;
                }
            }

            /* if there is an exit at point exitp, plug it and record a start point
            * at startp */

            void lookexit(Point exitp, Point startp)
            {
                if(maze[exitp.r][exitp.c] == ' ')
                {
                    addqueue(0, startp, startp);
                    maze[exitp.r][exitp.c] = '#';
                }
            }

            int main()
            {
                FILE *fin, *fout;
                Point p;
                int i, r, c, m, d;

                fin = fopen("maze1.in", "r");
                fout = fopen("maze1.out", "w");
                //assert(fin != NULL && fout != NULL);

                fscanf(fin, "%d %d\n", &wid, &ht);
                wid = 2*wid+1;
                ht = 2*ht+1;

                for(i=0; i<ht; i++)
                    fgets(maze[i], sizeof(maze[i]), fin);

                /* find exits */
                for(i=1; i<wid; i+=2)
                {
                    lookexit(Pt(0, i), Pt(1, i));
                    lookexit(Pt(ht-1, i), Pt(ht-2, i));
                }
                for(i=1; i<ht; i+=2)
                {
                    lookexit(Pt(i, 0), Pt(i, 1));
                    lookexit(Pt(i, wid-1), Pt(i, wid-2));
                }

                /* must have found at least one square with an exit */
                /* since two exits might open onto the same square, perhaps eq == 1 */

                for(bq = 0; bq < eq; bq++)
                {
                    p = floodq[bq].p;
                    d = floodq[bq].d;
                    dist[p.r][p.c] = d;

                    addqueue(d, p, Pt(p.r-2, p.c));
                    addqueue(d, p, Pt(p.r+2, p.c));
                    addqueue(d, p, Pt(p.r, p.c-2));
                    addqueue(d, p, Pt(p.r, p.c+2));
                }

                /* find maximum distance */
                m = 0;
                for(r=0; r<ht; r++)
                    for(c=0; c<wid; c++)
                        if(dist[r][c] > m)
                            m = dist[r][c];

                fprintf(fout, "%d\n", m);
                return 0;
            }

             

            很基礎的一個BFS或者是Floodfill問題,直接上標程吧。。。寫得太挫了。。

            posted on 2011-10-31 20:24 Sosi 閱讀(180) 評論(0)  編輯 收藏 引用

            統計系統
            伊人久久大香线蕉综合网站| 久久夜色撩人精品国产| 久久综合久久美利坚合众国| 无码任你躁久久久久久老妇App| 亚洲国产精品高清久久久| 99久久久精品免费观看国产| 久久一本综合| 久久国产精品一国产精品金尊| 99久久精品国产一区二区蜜芽| 久久精品国产AV一区二区三区| AV无码久久久久不卡网站下载 | 少妇被又大又粗又爽毛片久久黑人| 午夜精品久久久内射近拍高清| 精品久久久久久亚洲精品| 国产一区二区精品久久凹凸| 亚洲国产一成人久久精品| 国产精品成人99久久久久91gav| 狠狠色婷婷久久综合频道日韩 | 久久久久亚洲精品天堂久久久久久 | 欧美黑人又粗又大久久久| 久久se这里只有精品| 99999久久久久久亚洲| 亚洲人成电影网站久久| 日韩欧美亚洲综合久久影院d3| 久久亚洲AV成人无码国产| 亚洲欧美一级久久精品| 国产精品成人久久久久久久| 2021久久国自产拍精品| 国内精品人妻无码久久久影院导航| 久久最新免费视频| 国产亚洲成人久久| 中文字幕亚洲综合久久| 99久久超碰中文字幕伊人| 久久综合给久久狠狠97色 | 四虎国产精品免费久久5151| 色8久久人人97超碰香蕉987| 亚洲伊人久久精品影院| 久久无码AV中文出轨人妻| 久久久精品国产免大香伊| 久久精品亚洲AV久久久无码| 亚洲AV无码一区东京热久久|