Vijos 1119 Car's travel route _vijos

Source: Internet
Author: User
Describe

It is summer vacation again, the car that lives in city a wants to go to City B with a friend to travel. She knew that each city had four airfields, located on the four vertices of a rectangle, there is a straight high-speed railway between the two airports in the same city, the unit mileage price of the high speed railway in the first city is Ti, the airport of any two different cities has the route, the price of all route unit mileage is T.

So 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, set out and arrive at the airport in the city with arbitrary selection, requiring the least total cost.

Format input Format

The first line has four positive integers s,t,a,b. S (0<s<=100) represents the number of cities, T represents the price of aircraft unit mileage, A,B is the number of City A,b, (1<=a,b<=s).

Next there is the S row, where line I has 7 positive integers xi1,yi1,xi2,yi2,xi3,yi3,ti (XI1,YI1), (XI2,YI2), (XI3,YI3) are the coordinates of any three airports in the first city, T I for the first city High speed railway unit mileage price. Output format

Output minimum cost (result retains two decimal digits) sample sample input

3 1 3 1 1 1 3 3 1 2 5 7 4 5 2 1 8 6 8 8 11 6-
3
Sample output
47.55
Limit

1s source per test point

NOIP2001, question fourth.




It's obvious that this is a shortest problem. The shortest circuit is not the key point is the processing side

Because there are too many sides ... But also to find their own coordinates ...

Just be the Dijk's template question.


It is worth mentioning that the airport in the same city can also go ... No wonder, however, that the examples ...

#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath
> #include <iomanip> using namespace std;

const int inf=999999999;
    struct Self {int i;double D;
    BOOL operator< (const self &AMP;A1) const {return a1.d==d?a1.i<i:a1.d<d;

}
};
priority_queue<self>q;

Double d[511]; struct Side{int x,y;double W;}
S[400021];

int first[400021],nxt[400021]; struct Node{int x,y;}
G[511];

int w[511];
int m,n,start,end,cost;

int a,b,c;
    BOOL Chuizhi (int a,int b,int c) {int ax=g[b].x-g[a].x,bx=g[c].x-g[a].x;
    int ay=g[b].y-g[a].y,by=g[c].y-g[a].y;
    if (ax*bx+ay*by==0) return true;
return false;
    } void Findforth (int i) {int pos=i*4;
    int a=pos-3,b=pos-2,c=pos-1;
    if (Chuizhi (a,b,c)) {g[pos].x=g[b].x-g[a].x+g[c].x;g[pos].y=g[b].y-g[a].y+g[c].y;}
    if (Chuizhi (b,a,c)) {g[pos].x=g[a].x-g[b].x+g[c].x;g[pos].y=g[a].y-g[b].y+g[c].y;} if (Chuizhi (c,a,b)) {g[pos].x=g[a].x-g[c].x+g[b].x;g[POS].Y=G[A].Y-G[C].Y+G[B].Y;}
    } void makeside (int x,int y,double W) {n++;
    S[n].x=x;
    S[n].y=y;
    S[n].w=w;
    NXT[N]=FIRST[X];
First[x]=n;

Double dis (int a,int b,int c) {return sqrt ((g[a].x-g[b].x) * (g[a].x-g[b].x) + (G[A].Y-G[B].Y) * (G[A].Y-G[B].Y)) *c;}
    void Dijk () {int a,b;
    for (a=0;a<=m+4;a++) D[a]=inf;
    d[0]=0;
    Q.push ((self) {0,0});
        while (!q.empty ()) {self u=q.top (); Q.pop ();
        if (u.d!=d[u.i]) continue; 
            for (int e=first[u.i];e!=-1;e=nxt[e]) if (D[S[E].Y]&GT;D[U.I]+S[E].W) {D[S[E].Y]=D[U.I]+S[E].W;
        Q.push ((self) {S[E].Y,D[S[E].Y]});
    int main () {memset (first,-1,sizeof (a));

    memset (nxt,-1,sizeof (NXT));
    
    scanf ("%d%d%d%d", &m,&cost,&start,&end);
        for (a=1;a<=m;a++) {for (b=a*4-3;b<=a*4-1;b++) scanf ("%d%d", &g[b].x,&g[b].y);
        scanf ("%d", &w[a]);
        Findforth (a); for (b=a*4-3;b<=a*4;b+ +) for (c=a*4-3;c<=a*4;c++) if (b!=c) makeside (B,c,dis (b,c,w[a));
    
    } m*=4;
        
    for (a=1;a<=m;a++) for (b=1;b<=m;b++)//if (ABS (a-b) >=4) makeside (A,b,dis (a,b,cost));
    Makeside (0,start*4-3,0);
    Makeside (0,start*4-2,0);
    Makeside (0,start*4-1,0);
    
    Makeside (0,start*4,0);
    Makeside (end*4-3,m+1,0);
    Makeside (end*4-2,m+1,0);
    Makeside (end*4-1,m+1,0);

    Makeside (end*4,m+1,0);

    Dijk ();
    Cout<<fixed<<setprecision (2) <<d[m+1]<< ' \ n ';
return 0;
 }



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.