Zoj 1721 The Doors dijstra + computational ry

Source: Internet
Author: User

Practice: Well, it is very similar to the fzu question to find the point in the shortest path. The points on both sides of the door, the start point, and the end point are all drawn. Then, obtain the accessibility of each vertex Based on the graph.

#include<cstdio>#include<cmath>#define eps 1e8const int LMT=102;int wn,n;double gra[LMT][LMT];struct wall{double y1,y2,x;}w[LMT];struct point{double x,y;}p[LMT];inline double max(double a,double b){return a>b?a:b;}inline double min(double a,double b){return a<b?a:b;}inline double length(point a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}inline int min(int a,int b){return a<b?a:b;}void init(void){int i,j;for(i=0;i<LMT;i++)for(j=0;j<LMT;j++)gra[i][j]=eps;wn=0;n=0;}bool can(point a,point b){int i;if(a.x==b.x){for(i=0;i<wn&&w[i].x!=a.x;i++);for(;i<wn&&w[i].x==a.x;i++)if(a.y<=w[i].y1&&w[i].y2<=b.y)return 0;return 1;}double k=(b.y-a.y)/(b.x-a.x);for( i=0;i<wn&&w[i].x<=a.x;i++);for(;i<wn&&w[i].x<b.x;i++)if(b.y-k*(b.x-w[i].x)<=w[i].y2&&b.y-k*(b.x-w[i].x)>=w[i].y1)return 0;return 1;}int main(){int doors,i,j,k;double x,y1,y2,y3,y4;while(~scanf("%d",&doors)&&doors!=-1){init();p[n].x=0;p[n].y=5;n++;for( i=0;i<doors;i++){scanf("%lf%lf%lf%lf%lf",&x,&y1,&y2,&y3,&y4);p[n].x=x;p[n].y=y1;n++;p[n].x=x;p[n].y=y2;n++;p[n].x=x;p[n].y=y3;n++;p[n].x=x;p[n].y=y4;n++;w[wn].x=x;w[wn].y1=0;w[wn].y2=y1;wn++;w[wn].x=x;w[wn].y1=y2;w[wn].y2=y3;wn++;w[wn].x=x;w[wn].y1=y4;w[wn].y2=10;wn++;}p[n].x=10;p[n].y=5;n++;for(i=0;i<n;i++){for( j=i+1;j<n;j++)if(can(p[i],p[j]))gra[i][j]=gra[j][i]=length(p[i],p[j]);gra[i][i]=0;}        for(k=0;k<n;k++)for( i=0;i<n;i++)if(gra[i][k]!=eps)for(j=0;j<n;j++)if(gra[k][j]!=eps)   gra[i][j]=min(gra[i][j],gra[i][k]+gra[k][j]);printf("%.2lf\n",gra[0][n-1]);}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.