#include<algorithm> #include<cstring> #include<cstdio> #include<iostream> #include<cmath> #define ff 100000000 using namespace std; int s, t, a, b, m, q=1; double ss[405][405], x[405], y[405], ti[150], dis[405]; bool pd[405]; int main() { cin>>m; while(m--) { double ans=ff; cin>>s>>t>>a>>b; for(int i=1;i<=4*s;i++) for(int j=1;j<=4*s;j++) if(i!=j) ss[i][j]=ff; else ss[i][j]=0; for(int i=1;i<=s;i++) { double x1, x2, x3, y1, y2, y3; cin>>x1>>y1>>x2>>y2>>x3>>y3>>ti[i]; x[q]=x1;y[q]=y1;q++;x[q]=x2;y[q]=y2;q++;x[q]=x3;y[q]=y3;q++; if((x2-x1)*(x3-x1)+(y2-y1)*(y3-y1) == 0){ x[q]=x2+x3-x1;y[q]=y2+y3-y1;q++; } else if((x1-x2)*(x3-x2)+(y1-y2)*(y3-y2) == 0){ x[q]=x1+x3-x2;y[q]=y1+y3-y2;q++; } else if((x2-x3)*(x1-x3)+(y2-y3)*(y1-y3) == 0){ x[q]=x2+x1-x3;y[q]=y2+y1-y3;q++; } } for(int i=1;i<=4*s;i++) for(int j=1;j<=4*s;j++) { if((i-1)/4==(j-1)/4) ss[i][j]=(double)ti[(i-1)/4+1]*sqrt(pow(x[i]-x[j], 2)+pow(y[i]-y[j], 2)); else ss[i][j]=(double)t*sqrt(pow(x[i]-x[j], 2)+pow(y[i]-y[j], 2)); } for(int qq=4*(a-1)+1;qq<=4*a;qq++) { memset(pd, 0, sizeof(pd)); for(int i=1;i<=4*s;i++) dis[i]=ff; dis[qq]=0; for(int i=1;i<=4*s;i++) { int g=0, minn=ff; for(int j=1;j<=4*s;j++) if(pd[j]==0&&dis[j]<=minn) minn=dis[g=j]; pd[g]=1; for(int j=1;j<=4*s;j++) if(pd[j]==0) dis[j]=min(dis[j], dis[g]+ss[g][j]); } for(int j=4*(b-1)+1;j<=4*b;j++) ans=min(ans, dis[j]); } printf("%.1lf\n", ans); } return 0; }
car的旅行路线
最新推荐文章于 2024-07-02 15:26:42 发布