L-subway-poj 2502

Source: Internet
Author: User

Test instructions: In a city, there are several subway lines, each subway line has a number of stations, all the speed of the subway is 40km/h. Now that you know the coordinates of the origin and the end points, and the coordinates of each site of these subway lines, your walking speed is 10km/h, and you get to the subway at any station. Ask you how much time you need at least from the starting point to the end.

There are many sites, the data given is just a line, so you need to preprocess the data first, Increase the time required for any two-point person to walk. Data pre-processing is more troublesome ...


#include <stdio.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespaceStd

ConstintMAXN =100005;
ConstintOO =0xFFFFFFF;
ConstDoublevs = +* +/60.0;//how many meters per minute.
ConstDoubleVP =Ten* +/60.0;

structNode
{
intU, V, next;
DoubleC//time required between two points
}E[MAXN];
structPoint
{
intx, y;
}p[1005];

intNpoint, head[1005];
Doubledis[1005];
BOOLvis[1005];

DoubleLen (Point A, point B,DoubleV
{
returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y))/V;
}
voidADD (intUintVDoubleLenintK
{
e[k].u = u;
E[K].V = v;
E[K].C = Len;
E[k].next = Head[u];
Head[u] = k;
}
voidSPFA ()
{
stack<int> STA;
Sta.push (1);

while(Sta.size ())
{
inti = Sta.top (); Sta.pop ();
Vis[i] =false;

for(intJ=head[i]; j!=0; J=e[j].next)
{
intU = e[j].u, v = e[j].v;
Doublec = e[j].c;

if(Dis[u]+c < dis[v])
{
DIS[V] = Dis[u] + C;
if(Vis[v] = =false)
{
VIS[V] =true;
Sta.push (v);
}
}
}
}
}

intMain ()
{
intI, J, flag=0, k=1;

scanf"%d%d%d%d", &p[1].x, &p[1].Y, &p[2].x, &p[2].Y);

Npoint =3;
while(SCANF ("%d%d", &p[npoint].x, &p[npoint].y)! = EOF)
{
if(p[npoint].x! =-1)
{
if(Flag = =0)
Flag =1;
Else
{
Doublec = Len (P[npoint], p[npoint-1], VS);
ADD (Npoint, npoint-1, C, k++);
ADD (npoint-1, Npoint, C, k++);
}

npoint++;
}
Else
Flag =0;
}

for(i=1; i<npoint; i++)
for(j=i+1; j<=npoint; J + +)
{
Doublec = Len (P[i], p[j], VP);
Add (I, J, C, k++);
Add (J, I, C, k++);
}

for(i=2; i<npoint; i++)
Dis[i] = oo;

SPFA ();

printf"%.0f\n", dis[2]);

return0;
}

L-subway-poj 2502

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.