zoj 1891 Subway

zoj 1891 Subway,第1张

zoj 1891 Subway
#include<stdio.h>#include<math.h>#include<string.h>struct point{    double x;    double y;}home,temp,shul,pre,points[210];const double INF = 10e10;int main(void){    double mat[210][210];    int a,flag[210];    double dist[210],min;    int start,i,now,j;    while(scanf("%lf%lf%lf%lf",&home.x,&home.y,&shul.x,&shul.y)!=EOF)    {        points[1]=home;        points[2]=shul;        start=2;        for(i=1;i<210;i++) for(j=1;j<210;j++)     mat[i][j]=mat[j][i]=INF;        memset(flag,0,sizeof(flag));        for(i=1;i<210;i++) dist[i]=INF;        while(scanf("%lf%lf",&temp.x,&temp.y))        { if(temp.x+1<=10e-8 && temp.y+1<=10e-8) break; points[++start] = pre = temp; while(scanf("%lf%lf",&temp.x,&temp.y)) {     if(temp.x+1<=10e-8&& temp.y+1<=10e-8) break;     points[++start]=temp;     mat[start-1][start]=mat[start][start-1]         =sqrt((pre.x-temp.x)*(pre.x-temp.x)+(pre.y-temp.y)*(pre.y-temp.y))*3/2000;     pre=temp; }        }for(i=1;i<=start;i++) for(j=1;j<=start;j++) {     if(i==j) continue;     if(fabs(mat[i][j]-INF)<=10e-8)     {         mat[i][j]=mat[j][i]=         sqrt((points[i].x-points[j].x)*(points[i].x-points[j].x)+   (points[i].y-points[j].y)*(points[i].y-points[j].y))*3/500;     } }        now=1;dist[1]=0;flag[1]=1;        for(i=1;i<start;i++){for(j=1;j<=start;j++)if(flag[j] ==0 && dist[j] > dist[now] + mat[now][j])dist[j] = dist[now] + mat[now][j]; for(j=1,min=INF;j<=start;j++)if(dist[j] < min && flag[j] == 0){now=j;min=dist[j];}flag[now]=1;}a=(int)dist[2];        if(dist[2]-a>=0.5) a++;        printf("%dn",a);    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4898452.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存