-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnake ladder.cpp
More file actions
70 lines (58 loc) · 1.13 KB
/
snake ladder.cpp
File metadata and controls
70 lines (58 loc) · 1.13 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<bits/stdc++.h>
using namespace std;
struct ludo{
int num;
int dice;
};
int game(int n,int board[])
{
queue<ludo>q;
ludo l={0,0};
q.push(l);
bool *vis=new bool[n];
for(int i=0;i<n;i++)
vis[i]=false;
vis[0]=false;
ludo s;
while(!q.empty())
{
s=q.front();
int v=s.num;
q.pop();
if(v==n-1)
break;
for(int j=v+1;j<=v+6;j++)
{
if(!vis[j])
{
ludo k;
k.dice=s.dice+1;
vis[j]=true;
if(board[j]!=-1)
k.num=board[j];
else
k.num=j;
q.push(k);
}
}
}
return s.dice;
}
int main()
{
int n;
cin>>n;
int moves[n];
for(int i=0;i<n;i++)
moves[i]=-1;
moves[2] = 21;
moves[4] = 7;
moves[10] = 25;
moves[19] = 28;
// Snakes
moves[26] = 0;
moves[20] = 8;
moves[16] = 3;
moves[18] = 6;
cout<<game(n,moves)<<endl;
}