Lift hopping (Uva 10801 shortest)

Source: Internet
Author: User

Test instructions: N Elevator, 100 floor, tell each elevator speed and each elevator will stop the number of floors, starting point in the 0 floor, the end is the first level k, and each transfer need to wait 60 seconds, ask from 0 to K of the shortest time is how much.

Idea: This problem is read into the comparison of egg pain, and then according to the input after the completion of the diagram run Dijkstra. Add 60 seconds to the update.

Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define PI ACOs ( -1.0) #define EPS 1e-6# Define Lson rt<<1,l,mid#define Rson rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A; I <= b; i++) #define FREE ( I,A,B) for (i = A, I >= b; i--) #define FRL (i,a,b) for (i = A; I < b; i++) #define FRLL (i,a,b) for (i = A; i > b; i-- ) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d",         &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF Printf#define DBG PF ("hi\n") typedef long long ll;using namespace std; #define INF 0x3f3f3f3f#define mod 1000000009const int maxn = 105;const int MAXN = 3005;const int MAXM = 200010;const int N = 1005;int mp[maxn][maxn],time[6];int dist[maxn];bool vis[maxn];int n,k;char str[maxn];int a[maxn];int readLine (char *    s) {int L; for (l=0; (S[l]=getchar ())! = ' \ n ' &&s[L]!=EOF;    l++);    s[l]=0; return L;}    void Dijkstra () {int i,j,now,mi;    MEM (Dist,inf);    MEM (Vis,false);    for (i=0;i<100;i++) dist[i]=mp[0][i];    dist[0]=0;    Vis[0]=true;        for (i=0;i<100;i++) {now=-1;        Mi=inf;                for (j=0;j<100;j++) {if (!vis[j]&&mi>dist[j]) {now=j;            MI=DIST[J];        }}//printf ("now=%d\n", now);        if (now==-1) break;//DBG;        Vis[now]=true; for (j=0;j<100;j++) {if (!vis[j]&&dist[j]>dist[now]+mp[now][j]+60) dist[j]        =dist[now]+mp[now][j]+60;    }}//for (i=0;i<=30;i++)//PF ("%d", dist[i]);    if (dist[k]>=inf) pf ("impossible\n"); Else PF ("%d\n", Dist[k]);}    int main () {#ifndef Online_judge freopen ("C:/users/lyf/desktop/in.txt", "R", stdin), #endif int i,j;        while (~SFF (n,k)) {mem (mp,inf);        for (i=0;i<n;i++) SF (Time[i]);        GetChar ();            for (i=0;i<n;i++) {readLine (str);            int num=0,cnt=0;                while (SSCANF (Str+num, "%d", &a[cnt]) ==1) {cnt++;                while (str[num]&&str[num]== ') num++;            while (str[num]&&str[num]!= ') num++;            }//for (j=0;j<cnt;j++)//PF ("%d", a[j]);//cout<<endl; for (j=0;j<cnt;j++) for (int kk=j+1;kk<cnt;kk++) mp[a[j]][a[kk]]=mp[a[kk]][a[j]]=m        In (Mp[a[kk]][a[j]], (A[kk]-a[j]) *time[i]);    } Dijkstra (); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Lift hopping (Uva 10801 shortest)

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.