Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2018-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
adc2018
adc2018-system
Commits
ceb02064
Commit
ceb02064
authored
Aug 26, 2018
by
royus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add comment
parent
04f640e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
solver.c
source/solver.c
+15
-14
No files found.
source/solver.c
View file @
ceb02064
/* solver.c */
/* Last Change: 2018/08/26 (Sun)
05:44:44
. */
/* Last Change: 2018/08/26 (Sun)
14:46:21
. */
#define MAX_ATTEMPS 1000000
...
...
@@ -12,13 +12,13 @@
int
board
[
8
][
72
][
72
]
=
{};
int
avail
[
8
][
72
][
72
]
=
{};
//start=3,path=2,avail=1,nonavail=0,goal=-1
int
connected
[
8
*
72
*
72
/
2
+
1
]
=
{};
int
connected
[
8
*
72
*
72
/
2
+
1
]
=
{};
//connected[0]=(number of connected lines)
int
depth
,
height
,
width
;
int
lines
;
int
searchorder
[
6
];
int
searchorder
[
6
];
//x+-,y+-,z+-
//z,y,x
void
read
(
void
){
void
read
(
void
){
//read problem
int
x
,
y
,
z
,
i
;
char
c
,
str
[
8
];
scanf
(
" %s"
,
str
);
//SIZE
...
...
@@ -73,11 +73,11 @@ void read(void){
return
;
}
int
randline
(
void
){
//
1-lines -> 1-lines
int
randline
(
void
){
//
return random line number
return
rand
()
%
lines
+
1
;
}
int
available
(
int
startx
,
int
starty
,
int
startz
){
int
available
(
int
startx
,
int
starty
,
int
startz
){
//return 1 when (startx,starty,startz) can be connected to goal
if
(
avail
[
startz
][
starty
][
startx
]
==-
1
)
//goal
return
1
;
if
(
avail
[
startz
][
starty
][
startx
]
==
2
||
avail
[
startz
][
starty
][
startx
]
==
3
)
//visited
...
...
@@ -114,7 +114,7 @@ int available(int startx,int starty, int startz){
return
0
;
}
int
connectable
(
int
linea
,
int
lineb
){
int
connectable
(
int
linea
,
int
lineb
){
//return 1 if linea canbe connected when lineb is deleted
int
startx
=-
1
,
starty
=-
1
,
startz
=-
1
,
notfound
=
1
;
int
i
,
j
,
k
;
for
(
i
=
0
;
i
<
depth
;
i
++
)
...
...
@@ -129,30 +129,31 @@ int connectable(int linea,int lineb){
avail
[
startz
][
starty
][
startx
]
=
3
;
}
else
{
avail
[
i
][
j
][
k
]
=-
1
;
//goal
notfound
=
2
;
}
}
else
if
(
board
[
i
][
j
][
k
]
==
0
||
board
[
i
][
j
][
k
]
==
lineb
||
board
[
i
][
j
][
k
]
==
linea
){
avail
[
i
][
j
][
k
]
=
1
;
}
else
{
avail
[
i
][
j
][
k
]
=
0
;
}
if
(
startx
==-
1
||
starty
==-
1
||
startz
==-
1
){
if
(
startx
==-
1
||
starty
==-
1
||
startz
==-
1
||
notfound
!=
2
){
printf
(
"Error: Line %d
\n
"
,
linea
);
return
0
;
}
return
available
(
startx
,
starty
,
startz
);
}
void
connect
(
int
num
){
void
connect
(
int
line
){
//connect line
int
i
,
j
,
k
;
for
(
i
=
0
;
i
<
depth
;
i
++
)
for
(
j
=
0
;
j
<
height
;
j
++
)
for
(
k
=
0
;
k
<
width
;
k
++
)
if
(
avail
[
i
][
j
][
k
]
==
2
&&
board
[
i
][
j
][
k
]
==
0
)
board
[
i
][
j
][
k
]
=
num
;
board
[
i
][
j
][
k
]
=
line
;
return
;
}
void
delete
(
int
line
){
void
delete
(
int
line
){
//delete line
int
i
,
j
,
k
;
for
(
i
=
0
;
i
<
depth
;
i
++
)
for
(
j
=
0
;
j
<
height
;
j
++
)
...
...
@@ -164,11 +165,11 @@ void delete(int line){
int
solve
(
void
){
//return 1 when solved, 0 when cannot
int
i
,
j
,
linea
,
lineb
;
for
(
i
=
0
;
i
<
MAX_ATTEMPS
;
i
++
){
for
(
i
=
0
;
i
<
MAX_ATTEMPS
;
i
++
){
//try to connect MAX_ATTEMPS times
linea
=
randline
();
if
(
connected
[
linea
])
continue
;
if
(
connectable
(
linea
,
0
)){
if
(
connectable
(
linea
,
0
)){
//if linea canbe conneced without deleting lines
connect
(
linea
);
connected
[
linea
]
=
1
;
connected
[
0
]
++
;
...
...
@@ -176,7 +177,7 @@ int solve(void){ //return 1 when solved, 0 when cannot
return
1
;
}
else
{
for
(
j
=
0
;
j
<
MAX_ATTEMPS
;
j
++
){
for
(
j
=
0
;
j
<
MAX_ATTEMPS
;
j
++
){
//try to find a line to delete
lineb
=
randline
();
if
(
connectable
(
linea
,
lineb
)){
delete
(
lineb
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment