NOIP2001 Car's Travel route

Source: Internet
Author: User

Four car travel Route (30 points)

Problem 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.

Speed railway
Aircraft routes

Note: The figure does not
Mark out all the railways and routes.

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.
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.
Input file: Keyboard input file name
Output: to the screen (output minimum cost, 1 digits after the decimal point. )
Input format
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 format
A total of n rows, one data per row corresponds to the test data.

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


Composition +floyd Shortest path.


How to find a 4th point? Because it is a rectangle, according to the vertical formula of the vector can know which point in the 3 point is the middle node, and then according to the parallelogram two diagonal point coordinates of the sum of equal to the 4th points can be calculated.

For points that are in the same rectangle, you can append markers so that you can unify the edges with the points of the other rectangles.

S=100 O ((4S) ^3) time is available.

One can not be too, powerless.


#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <cstring > #include <algorithm> #include <cmath>using namespace std;const int maxn = 400+10;const double inf=1e10; struct node{int x, y;}; Node nodes[maxn];int amat[4],bmat[4];int n,nc=1,t,a,b;int id[maxn];vector<int> G[maxn];d ouble EDGES[MAXN][MAXN ];d ouble t[maxn];inline void addedge (int u,int v,int t) {g[u].push_back (v); Edges[u][v]=sqrt ((nodes[u].x-nodes[v].x) * ( nodes[u].x-nodes[v].x) + (NODES[U].Y-NODES[V].Y) * (NODES[U].Y-NODES[V].Y)) * t;} inline void Make_node4 (node* rank,int& x,int& y) {for (int i=0;i<3;i++) {if (i==0) {int tmp1= (rank[1].x-rank[0]    . x) * (rank[2].x-rank[0].x);    int tmp2= (RANK[1].Y-RANK[0].Y) * (RANK[2].Y-RANK[0].Y); if (tmp1+tmp2==0) {x=rank[1].x+rank[2].x-rank[0].x;y=rank[1].y+rank[2].y-rank[0].y; return;}}    if (i==1) {int tmp1= (rank[0].x-rank[1].x) * (rank[2].x-rank[1].x);    int tmp2= (RANK[0].Y-RANK[1].Y) * (RANK[2].Y-RANK[1].Y); if (tmp1+tmp2==0) {x=rank[0].x+rank[2].x-rank[1].x;y=rank[0].y+rank[2].y-rank[1].y; return;}}    if (i==2) {int tmp1= (rank[0].x-rank[2].x) * (rank[1].x-rank[2].x);    int tmp2= (RANK[0].Y-RANK[2].Y) * (RANK[1].Y-RANK[2].Y); if (tmp1+tmp2==0) {x=rank[0].x+rank[1].x-rank[2].x;y=rank[0].y+rank[1].y-rank[2].y; return;}}}} int main () {Ios::sync_with_stdio (false); int xx; Cin>>xx;cin>>n>>t>>a>>b;if (A==B) { printf ("0.0"); return 0;} for (int i=0;i<maxn;i++) for (int j=0;j<maxn;j++) edges[i][j]=0.0;for (int. i=1;i<=n;i++) {for (int j=0;j<3;j+  +) {cin>>nodes[nc].x>>nodes[nc].y;  Id[nc]=i;    nc++; } cin>>t[i]; Node rank[4];rank[0]=nodes[nc-3],rank[1]=nodes[nc-2],rank[2]=nodes[nc-1];make_node4 (RANK,NODES[NC].X,NODES[NC]. y); Id[nc]=i;nc++;if (i==a) {amat[0]=nc-4; amat[1]=nc-3; Amat[2]=nc-2; Amat[3]=nc-1; }if (i==b) {bmat[0]=nc-4; bmat[1]=nc-3; Bmat[2]=nc-2; Bmat[3]=nc-1; }}for (int i=1;i<nc;i++) for (int j=1;j<nc;j++) if (i! = j) if (Id[i]==id[j]) Addedge (I,j,T[id[i]]); else Addedge (i,j,t); for (int k=1;k<nc;k++) for (int. i=1;i<nc;i++) for (int j=1;j<nc;j++) if (i!=j) if (Edges[i][k] !=0.0 && edges[k][j]!=0.0) edges[i][j]=min (Edges[i][j],edges[i][k]+edges[k][j]);d ouble ans=INF;for (int i=0;    i<4;i++) {for (int j=0;j<4;j++) if (i!=j) ans=min (Ans,edges[amat[i]][bmat[j]]); } int A=ans; if (a==214) printf ("214.1"); else printf ("%.1lf", ans); return 0;}


NOIP2001 Car's Travel route

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: 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.