Travel directions for car (Codevs 1041)

Source: Internet
Author: User

Title Description Description

Again to summer vacation, live in city a car want to go with friends to City B travel. She knows that each city has four airports, located in a rectangle of four vertices, the same city, two airports have a straight high-speed rail, the first city in the high-speed railway unit mileage price of TI, any two different cities have a route between the airport, all routes unit mileage price is T.

How should car arrange the route to City B to save as much as possible? She found it was not a simple question, so she came to you for advice.
Task
Find a tourist route from City A to B, and airports in the city of departure and arrival can be arbitrarily selected, requiring the lowest total cost.

Enter a description Input Description

The first behavior is a positive integer n (0<=n<=10), which indicates that there are n sets of test data.
The first row of each group has four positive integer s,t,a,b.
S (0<s<=100) represents the number of cities, T represents the price of the aircraft unit mileage, A, B is the number of city A, B, (1<=a,b<=s).
Next is the S-line, where line I has 7 positive integer xi1,yi1,xi2,yi2,xi3,yi3,ti, in which (XI1,YI1), (XI2,YI2), (XI3,YI3) are the coordinates of any three airports in the first I city, T I is the price of the first city High speed railway unit mileage.

Output description Output Description

A total of n rows, one data per row corresponds to the test data.

Sample input Sample Input

1
3 10 1 3
1 1 1 3 3 1 30
2 5 7 4 5 2 1
8 6 8 8 11 6 3

Sample output Sample Output

47.5

/*Pre- treatment of violence and floyed for shortest-circuit pretreatment: expanding n cities into 4*n airfields, Belong[i] indicates which city the first airport belongs to map[][] storage distance between airfields for floyed update*/#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#defineM 410#defineINF 9999999using namespacestd;Doublex[m],y[m],map[m][m],t;intbelong[m],n,a,b,tot=0;voidGet_four (intIinten) {    intr1=tot-2, r2=tot-1, r3=TOT,RR; MAP[R1][R2]=map[r2][r1]=pow (X[R1]-X[R2],2) +pow (Y[R1]-Y[R2],2); MAP[R1][R3]=map[r3][r1]=pow (X[R1]-X[R3],2) +pow (Y[R1]-Y[R3],2); MAP[R3][R2]=map[r2][r3]=pow (X[R3]-X[R2],2) +pow (Y[R3]-Y[R2],2); if(MAP[R1][R2]+MAP[R1][R3]==MAP[R2][R3]) rr=R1; Else if(MAP[R1][R2]+MAP[R2][R3]==MAP[R1][R3]) rr=R2; ElseRr=R3; Tot++; if(RR==R1) {Doublexx=x[r1]-x[r2],yy=y[r1]-y[r2];x[tot]=x[r3]-xx;y[tot]=y[r3]-yy;} if(RR==R2) {Doublexx=x[r1]-x[r2],yy=y[r1]-y[r2];x[tot]=x[r3]+xx;y[tot]=y[r3]+yy;} if(RR==R3) {Doublexx=x[r1]-x[r3],yy=y[r1]-y[r3];x[tot]=x[r2]+xx;y[tot]=y[r2]+yy;}  for(intj=tot-3; j<=tot;j++)       for(intk=tot-3; k<j;k++) Map[j][k]=map[k][j]=sqrt (Pow (x[j]-x[k),2) +pow (Y[j]-y[k],2))*en; Belong[tot]=i;}voidfloyed () { for(intk=1; k<=tot;k++)       for(intI=1; i<=tot;i++)         for(intj=1; j<=tot;j++)          if(i!=j&&i!=k&&j!=k) Map[i][j]=min (map[i][k]+Map[k][j],map[i][j]); Doubleans=INF;  for(intI=1; i<=tot;i++)        for(intj=1; j<=tot;j++)        if(belong[i]==a&&belong[j]==B) ans=min (Map[i][j],ans); printf ("%.1lf\n", ans);}voidWork () {scanf ("%d%lf%d%d",&n,&t,&a,&B);  for(intI=1; i<=n;i++)    {         for(intj=1; j<=3; j + +) {tot++; scanf ("%LF%LF",&x[tot],&Y[tot]); Belong[tot]=i; }        intx; scanf ("%d",&x);    Get_four (I,X); }     for(intI=1; i<=tot;i++)       for(intj=1; j<i;j++)        if(belong[i]!=Belong[j]) map[i][j]=map[j][i]=sqrt (Pow (x[i]-x[j),2) +pow (Y[i]-y[j],2))*T; Floyed ();}intMain () {intT; scanf ("%d",&T);  while(t--) {memset (map,0,sizeof(map)); memset (x,0,sizeof(x)); memset (Y,0,sizeof(y)); Memset (Belong,0,sizeof(belong));    Work (); }    return 0;}
View Code

Car's Travel route (Codevs 1041)

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.