-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled5.cpp
More file actions
33 lines (31 loc) · 767 Bytes
/
Untitled5.cpp
File metadata and controls
33 lines (31 loc) · 767 Bytes
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
#include <stdio.h>
#include <queue>
#include <set>
#include <cstdio>
using namespace std;
set<int> m;
priority_queue<pair<int,int> ,vector<pair<int,int> >,greater<pair<int,int> > >q;
int main(){
int arr[]={0,-1,0,-2,8,-2,0,-2,0};
q.push(make_pair(0,0));
while(!q.empty()){
printf("%d %d\n",q.top().first,q.top().second);
m.insert(q.top().first);
if(q.top().first>=8){
printf("%d",q.top().second);
return 0;
}
if(arr[q.top().first]==0){
for(int i=1;i<=6;i++){
if(m.find(q.top().first+i)==m.end()){
q.push(make_pair(q.top().first+i,q.top().second+1));
}
}
}else{
if(m.find(q.top().first+arr[q.top().first])==m.end()){
q.push(make_pair(q.top().first+arr[q.top().first],q.top().second));
}
}
q.pop();
}
}