一点难但不多
2024-08-21 20:08:25
发布于:广东
#include <bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
}City[105][5];
int mon[105];
double Mon[105][5][105][5];
double way(node a,node b)
{
return sqrt(pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0));
}
void four(int o)
{
double p[4];
int maxx;
int maxn=0;
for(int i=1;i<=2;i++)
{
for(int j=i+1;j<=3;j++)
{
p[6-i-j]=way(City[o][i],City[o][j]);
if(p[6-i-j]>maxn)
{
maxn=p[6-i-j];
maxx=6-i-j;
}
}
}
swap(City[o][maxx],City[o][1]);
City[o][4].x=City[o][2].x+City[o][3].x-City[o][1].x;
City[o][4].y=City[o][2].y+City[o][3].y-City[o][1].y;
}
int A,B,S,T,t;
double minn=1000000;
int main()
{
scanf("%d",&t);
for(;t;t--)
{
scanf("%d %d %d %d",&S,&T,&A,&B);
for(int i=1;i<=S;i++)
{
for(int j=1;j<=3;j++)
{
scanf("%d %d",&City[i][j].x,&City[i][j].y);
}
scanf("%d",&mon[i]);
four(i);
}
if(AB)
{
printf("0.00\n");
continue;
}
for(int i=1;i<=S;i++)
{
for(int j=1;j<=4;j++)
{
for(int k=1;k<=S;k++)
{
for(int l=1;l<=4;l++)
{
if(ik)
{
Mon[i][j][k][l]=way(City[i][j],City[k][l])*mon[i];
}
else
{
Mon[i][j][k][l]=way(City[i][j],City[k][l])*T;
}
}
}
}
}
for(int i=1;i<=S;i++)
{
for(int in=1;in<=4;in++)
{
for(int j=1;j<=S;j++)
{
for(int jn=1;jn<=4;jn++)
{
for(int k=1;k<=S;k++)
{
for(int kn=1;kn<=4;kn++)
{
if(Mon[j][jn][i][in]+Mon[i][in][k][kn]<Mon[j][jn][k][kn])
{
Mon[j][jn][k][kn]=Mon[j][jn][i][in]+Mon[i][in][k][kn];
}
}
}
}
}
}
}
for(int i=1;i<=4;i++)
{
for(int j=1;j<=4;j++)
{
if(Mon[A][i][B][j]<minn)
{
minn=Mon[A][i][B][j];
}
}
}
printf("%.2lf\n",minn);
minn=1000000;
return 0;
}
}
这里空空如也
有帮助,赞一个