From b97593b9d99d5282d7f39a787798776dfc63ffa8 Mon Sep 17 00:00:00 2001 From: vijay532 Date: Tue, 1 Oct 2019 22:11:12 +0530 Subject: [PATCH] https://www.spoj.com/problems/ELEVTRBL/ --- ELEVTRBL.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ELEVTRBL.cpp diff --git a/ELEVTRBL.cpp b/ELEVTRBL.cpp new file mode 100644 index 0000000..8104a30 --- /dev/null +++ b/ELEVTRBL.cpp @@ -0,0 +1,56 @@ +//g++ 5.4.0 + +#include +#define ll long long +using namespace std; +/* +10 1 10 2 1 +*/ +ll s,g,u,d,f; +ll mark[1000001]; +ll dist[1000001]; +void compute() +{ + //cout<q; + q.push(s); + dist[s]=0; + mark[s]=1; + while(!q.empty()) + { + current=q.front(); + q.pop(); + next_up=current+u; + next_down=current-d; + //cout<=1 && !mark[next_down]) + { + mark[next_down]=1; + q.push(next_down); + dist[next_down]=dist[current]+1; + } + //cout<>f>>s>>g>>u>>d; + dist[g]=-1; + compute(); + if(dist[g]==-1) + { + cout<<"use the stairs"; + } + else + { + cout<