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

            poj1556

            The Doors

            Time Limit: 1000MS Memory Limit: 10000K
            Total Submissions: 3721 Accepted: 1604

            Description

            You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will always have sides at x = 0, x = 10, y = 0, and y = 10. The initial and final points of the path are always (0, 5) and (10, 5). There will also be from 0 to 18 vertical walls inside the chamber, each with two doorways. The figure below illustrates such a chamber and also shows the path of minimal length.

            Input

            The input data for the illustrated chamber would appear as follows.

            2
            4 2 7 8 9
            7 3 4.5 6 7

            The first line contains the number of interior walls. Then there is a line for each such wall, containing five real numbers. The first number is the x coordinate of the wall (0 < x < 10), and the remaining four are the y coordinates of the ends of the doorways in that wall. The x coordinates of the walls are in increasing order, and within each line the y coordinates are in increasing order. The input file will contain at least one such set of data. The end of the data comes when the number of walls is -1.

            Output

            The output should contain one line of output for each chamber. The line should contain the minimal path length rounded to two decimal places past the decimal point, and always showing the two decimal places past the decimal point. The line should contain no blanks.

            Sample Input

            1
            5 4 6 7 8
            2
            4 2 7 8 9
            7 3 4.5 6 7
            -1

            Sample Output

            10.00
            10.06
            這是黑書上的題目,貌似簡化了些
            做法就不解釋了
            主要是處理細節(jié),主要判斷線段是否相交//只考慮規(guī)范相交即可
             
            構(gòu)圖后求最短路即可
             
            #include<algorithm>
            #include
            <iostream>
            #include
            <string>
            #include
            <math.h>
            #define inf 0x7ffffff
            #define max 100
            using namespace std;
            int n;
            struct point
            {
                
            double x,y;
            }
            ;
            struct node
            {
                
            int u,v;
            }
            ;
            double wx[20];//每堵墻x坐標
            point p[max];
            int psize;
            double py[20][4];
            double g[max][max];
            node e[max
            *max];
            int esize;
            double dis(point a,point b)
            {
                
            return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
            }

            double cross(double x1,double y1,double x2,double y2,double x3,double y3)//判斷point3在線段(1,2)上面還是下面,叉積
            {
                
            return (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
            }

            bool isok(point a,point b)//判斷兩點之間能不能連邊
            {
                
            if (a.x>=b.x) return false;
                
            bool flag=true;
                
            int i;
                i
            =0;
                
            while (wx[i]<=a.x&&i<n) i++;
                
            while(wx[i]<b.x && i<n)
                
            {
                    
            if (   cross(a.x,a.y,b.x,b.y,wx[i],0)*cross(a.x,a.y,b.x,b.y,wx[i],py[i][0])<0
                        
            || cross(a.x,a.y,b.x,b.y,wx[i],py[i][1])*cross(a.x,a.y,b.x,b.y,wx[i],py[i][2])<0
                        
            || cross(a.x,a.y,b.x,b.y,wx[i],py[i][3])*cross(a.x,a.y,b.x,b.y,wx[i],10)<0)
                    
            {
                        flag
            =false;
                        
            break;
                    }

                    i
            ++;
                }

                
            return flag;
            }

            double bellmanford(int beg,int end)//求最短路 這里邊數(shù)相對較少,也可用spfa,或其他
            {
                
            bool ex=true;
                
            double d[max];
                
            int i,j;
                
            for(i=0;i<max;i++) d[i]=inf;
                d[beg]
            =0;
                
            for(i=0;i<psize && ex;i++)
                
            {
                    ex
            =false;
                    
            for(j=0;j<esize;j++)
                    
            {
                        
            if (d[e[j].u]<inf  && d[e[j].v]>d[e[j].u]+g[e[j].u][e[j].v])
                        
            {
                            d[e[j].v]
            =d[e[j].u]+g[e[j].u][e[j].v];
                            ex
            =true;
                        }

                    }

                }

                
            return d[end];
            }

            void solve()
            {
                
            int i,j;
                p[
            0].x=0;
                p[
            0].y=5;
                psize
            =1;
                
            for(i=0; i<n; i++)
                
            {
                    scanf(
            "%lf",&wx[i]);
                    
            for(j=0; j<4; j++)
                    
            {
                        p[psize].x
            =wx[i];
                        scanf(
            "%lf",&p[psize].y);
                        py[i][j]
            =p[psize].y;
                        psize
            ++;
                    }

                }

                p[psize].x
            =10;
                p[psize].y
            =5;
                psize
            ++;
                
            for(i=0; i<psize; i++)
                
            {
                    
            for(j=0; j<psize; j++)
                    
            {
                        g[i][j]
            =inf;
                    }

                }

                esize
            =0;
                
            for(i=0; i<psize; i++)
                    
            for(j=i+1; j<psize; j++)
                    
            {
                        
            if (isok(p[i],p[j]))
                        
            {
                            g[i][j]
            =dis(p[i],p[j]);
                            e[esize].u
            =i;
                            e[esize].v
            =j;
                            esize
            ++;
                        }

                    }

                printf(
            "%.2lf\n",bellmanford(0,psize-1));
            }

            int main()
            {
                
            while(scanf("%d",&n)!=EOF&&n!=-1)
                
            {
                    solve();
                }

                
            return 0;
            }

             

            posted on 2012-04-03 00:53 jh818012 閱讀(274) 評論(0)  編輯 收藏 引用


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


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點擊標題查看
            • --王私江
            久久青青草原综合伊人| 久久婷婷激情综合色综合俺也去| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 伊人精品久久久久7777| 亚洲欧洲精品成人久久奇米网| 欧美日韩精品久久久免费观看| 久久综合亚洲色HEZYO国产| 女人高潮久久久叫人喷水| 久久综合亚洲色HEZYO社区| 久久久久亚洲Av无码专| 久久久久久久亚洲精品| 无码人妻久久久一区二区三区| 成人妇女免费播放久久久| 三级片免费观看久久| 欧美一区二区三区久久综| 99久久国产免费福利| 思思久久99热只有频精品66| 久久精品国产亚洲av影院| 看全色黄大色大片免费久久久| 少妇高潮惨叫久久久久久| 91久久国产视频| 久久婷婷五月综合色奶水99啪| 日本精品一区二区久久久| 久久99精品久久只有精品| 日本精品一区二区久久久| 久久91综合国产91久久精品| 久久婷婷色综合一区二区| 一本大道加勒比久久综合| 色婷婷综合久久久中文字幕 | 日本久久中文字幕| 久久99国产精品二区不卡| 久久久无码精品亚洲日韩蜜臀浪潮| 久久青青草原综合伊人| 久久99精品久久只有精品| 伊人久久综合精品无码AV专区 | 中文国产成人精品久久亚洲精品AⅤ无码精品 | 国产精品久久久久一区二区三区| 三上悠亚久久精品| 97视频久久久| 性做久久久久久久久浪潮| 99热成人精品免费久久|