-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathELEVTRBL.cpp
More file actions
55 lines (51 loc) · 1.25 KB
/
ELEVTRBL.cpp
File metadata and controls
55 lines (51 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<stdio.h>
//#include<conio.h>
#include<queue>
#include<string.h>
using namespace std;
queue <int> floor;
int f,s,g,u,d,flag=0,count=0,fs,i,temp;
int a[1000005];
int main()
{
scanf("%d%d%d%d%d",&f,&s,&g,&u,&d);
floor.push(s);
memset(a,0,sizeof(a));
while(!floor.empty())
{
fs=floor.size();
for(i=0;i<fs;i++)
{
temp=floor.front();
if(temp==g)
{
flag=1;
break;
}
else
{
if(temp+u<=f && a[temp+u]==0)
{
floor.push(temp+u);
a[temp+u]=1;
}
if(temp-d>0 && a[temp-d]==0)
{
floor.push(temp-d);
a[temp-d]=1;
}
}
a[temp]=1;
floor.pop();
}
if(flag==1)
break;
count++;
}
if(flag==1)
printf("%d",count);
else
printf("use the stairs");
// getch();
}