-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathclocks.cpp
More file actions
139 lines (117 loc) · 2.39 KB
/
Copy pathclocks.cpp
File metadata and controls
139 lines (117 loc) · 2.39 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
ID: xieke.b1
PROG: clocks
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <string.h>
using namespace std;
ofstream fout("clocks.out");
ifstream fin ("clocks.in");
//int s[9];
vector<int> start;
vector<int> final;
string for_test = "112224";
const int MAXN = 1200000;
string dir[10]={
"",
"ABDE",
"ABC",
"BCEF",
"ADG",
"BDEFH",
"CFI",
"DEGH",
"GHI",
"EFHI"
};
int szs[10] = {
0,
4,3,4,3,5,3,4,3,4};
bool should_return;
//char path[50];
int compute(vector<int> &s){
int res = 0;
for(int i=0; i<9; i++){
res = res*4+s[i];
}
return res;
}
//void dfs(vector<int> s, int depth, int p_path){
void print(vector<int> s){
for(int i=0; i<s.size(); i++){
cout<<s[i]<<" ";
}
cout<<endl;
}
void dfs(vector<int> s, int depth, string path){
if(should_return){
return ;
}
int t = compute(s);
cout<<path<<endl;
//cout<<"now path is "<<path<<endl;
if(s==final){
cout<<"in !!!"<<endl;
//for(int i=0; i<p_path-1; i++)fout<<path[i]<<" ";
//fout<<path[p_path-1]<<endl;
fout<<path<<endl;
should_return = true;
return ;
}
if(path==for_test){
cout<<"i could go here"<<endl;
}
if(depth<=0){
return ;
}
//cout<<"depth = "<<depth<<endl;
/*
cout<<"now state is ";
for(int i=0; i<s.size(); i++){
cout<<s[i];
}cout<<endl;
*/
for(int i=1; i<=9; i++){
int sz = szs[i];
vector<int> ns=s;
for(int j=0; j<sz; j++){
int pos = dir[i][j]-'A';
ns[pos]+=1;
if(ns[pos]==4)ns[pos]=0;
//ns[pos]%=12;
}
if(path==for_test){
cout<<"after change state is "<<endl;
print(ns);
}
//path[p_path] = char('0'+i);
//string np = path+char('0'+i);
//dfs(ns, depth-1, p_path+1);
dfs(ns, depth-1, path+char('0'+i));
}
}
void work(){
should_return = false;
for(int depth=10; depth<=20; depth++){
cout<<"depth is "<<depth<<endl;
dfs(start, depth, "");
if(should_return){
return ;
}
}
}
int main(){
for(int i=0; i<9; i++){
int t;
fin>>t;
start.push_back((t/3)%4);
final.push_back(0);
//fin>>s[i];
}
work();
return 0;
}