Lift Hopping)

Source: Internet
Author: User

Lift Hopping)

Meaning: n elevators and 100 floors tell the speed of each elevator and the number of floors where each elevator will stop. the start point is at Layer 0, and the end point is at Layer k, in addition, you need to wait 60 seconds for each transfer and ask the shortest time from 0 to k.

Idea: This is to read the question, it hurts, and then run Dijkstra after creating a graph based on the input. Add 60 seconds to the update.

Code:

 

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     #include 
     
      #include
      #include 
       
        #include 
        
         #include 
         
          #include 
          
           #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)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())!=''&&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,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); else pf(%d,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
           
            

 

 

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.