Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nszw-solver
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
adc2019
nszw-solver
Commits
ca00a809
You need to sign in or sign up before continuing.
Commit
ca00a809
authored
Aug 25, 2019
by
makoto.nishizawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add README
parent
57afb03f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
56 deletions
+47
-56
README
README
+14
-0
router.cpp
router/router.cpp
+2
-2
solve
solve
+0
-0
solver.cpp
solver.cpp
+31
-54
No files found.
README
View file @
ca00a809
makeで実行ファイルsolverができます.
MAKEFILE
g++ -o solve solver.cpp main.cpp io.c router/router.cpp -std=c++11
./solver < QUESTIONFILEで実行され解答のみを出力します.
必要ヘッダ
<limits.h>
<stdio.h>
<vector>
<algorithm>
"solver.h"
"io.h"
"router/router.hpp"
\ No newline at end of file
router/router.cpp
View file @
ca00a809
...
...
@@ -73,7 +73,7 @@ int router(short int size_x, short int size_y, short int line_num, short int boa
lfsr_random_init
(
seed
);
// Step 1
cout
<<
"1st routing ..."
<<
endl
;
//
cout << "1st routing ..." << endl;
for
(
i
=
0
;
i
<
line_num
;
i
++
)
{
if
(
adjacents
[
i
])
continue
;
#ifdef PRINT_SEARCH
...
...
@@ -90,7 +90,7 @@ int router(short int size_x, short int size_y, short int line_num, short int boa
ap_uint
<
1
>
overlap_checks
[
MAX_CELLS
];
// Step 2
cout
<<
"rip-up routing ..."
<<
endl
;
//
cout << "rip-up routing ..." << endl;
short
int
last_target
=
-
1
;
ap_uint
<
16
>
round
;
for
(
round
=
1
;
round
<=
ROUND_LIMIT
;
round
++
)
{
...
...
solve
View file @
ca00a809
No preview for this file type
solver.cpp
View file @
ca00a809
...
...
@@ -5,8 +5,10 @@
#include"solver.h"
#include"io.h"
#include<stdio.h>
#include <list>
#include <bits/stdc++.h>
//#include <list>
#include <vector>
#include <algorithm>
//#include <bits/stdc++.h>
#include "router/router.hpp"
/* #include<stdlib.h> */
/* #include<string.h> */
...
...
@@ -38,9 +40,9 @@ void show_blocks(){
int
data
[
4
][
4
];
int
i
,
j
,
k
;
for
(
i
=
1
;
i
<
blocks
;
i
++
){
printf
(
"block #%d
\n
"
,
i
);
//
printf("block #%d\n",i);
for
(
j
=
1
;
j
<=
4
;
j
++
){
printf
(
"x:%d y:%d edge:%d
\n
"
,
block_data
[
i
][
j
][
0
],
block_data
[
i
][
j
][
1
],
block_data
[
i
][
j
][
2
]);
//
printf("x:%d y:%d edge:%d\n",block_data[i][j][0],block_data[i][j][1],block_data[i][j][2]);
}
}
return
;
...
...
@@ -132,7 +134,7 @@ int check_put_mino(int i,int x, int y,int flag){// check block#i can put on x,y
int
data_mino
(
int
i
,
int
x
,
int
y
,
int
flag
){
std
::
cout
<<
"put mino "
<<
i
<<
" on "
<<
x
<<
" "
<<
y
<<
std
::
endl
;
//
std::cout << "put mino "<< i << " on " << x <<" " << y << std::endl;
for
(
int
j
=
0
;
j
<
100
;
j
++
){
if
(
check_put_mino
(
i
,
x
,
y
,
flag
)){
for
(
int
l
=
1
;
l
<
5
;
l
++
){
...
...
@@ -191,13 +193,13 @@ void put_mino(){
}
if
(
index
==-
1
){
for
(
index
=
blocks
;
index
>
0
;
index
--
){
std
::
cout
<<
done_block
[
index
];
//
std::cout << done_block[index];
if
(
done_block
[
index
]
==
0
){
next
=
index
;
break
;
}
}
std
::
cout
<<
endl
;
//
std::cout << endl;
if
(
index
==
0
)
break
;
// if all blocks are searched
}
if
(
index
==-
1
)
break
;
// if all blocks are searched
...
...
@@ -310,7 +312,7 @@ void put_mino(){
printf
(
"
\n\n
start making order of height
\n
"
);
//
printf("\n\nstart making order of height\n");
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
){
//init status
check_block
[
i
]
=
0
;
done_block
[
i
]
=
0
;
...
...
@@ -445,7 +447,7 @@ void put_mino(){
//if(x==1)break;
}
//end of while ture for height
printf
(
"width is
\n
"
);
/*
printf("width is \n");
for(int i=0;i<order_w.size();i++){
printf("%d ",order_w[i]);
}
...
...
@@ -456,7 +458,7 @@ void put_mino(){
printf("%d ",order_h[i]);
}
printf("\n");
*/
int
put_block
[
100
];
int
height_c
=
0
,
width_c
=
1
;
int
next_put
=
1
;
...
...
@@ -476,7 +478,7 @@ void put_mino(){
max_w
=
block_data
[
order_w
[
j
]][
k
][
0
];
}
}
std
::
cout
<<
"add "
<<
order_w
[
j
]
<<
" mino "
<<
max_w
+
1
<<
std
::
endl
;
//
std::cout<< "add " << order_w[j] << " mino " << max_w+1 << std::endl;
width_c
+=
max_w
+
1
;
width_c
+=
SPACE
;
}
...
...
@@ -490,34 +492,9 @@ void put_mino(){
}
height_c
+=
max_h
+
1
;
}
print_answer
();
//
print_answer();
//int next;
int
mino_x
,
mino_y
;
/*for(int i=0;i<blocks;i++){
next=mino_order[i];
mino_x=block_data[i][0][0];
mino_y=block_data[i][0][1];
del_mino(next);
if(i%2){
for(int j=mino_x-1;j>1;j--){
if(check_put_mino(next,j,mino_y)){
mino_x=j;
}else{
break;
}
}
}else{
for(int j=mino_y-1;j>1;j--){
if(check_put_mino(next,mino_x,j)){
mino_y=j;
}else{
break;
}
}
}
data_mino(next,mino_x,mino_y);
}*/
}
void
make_board_str
(
int
size_x
,
int
size_y
){
for
(
int
y
=
0
;
y
<
size_y
;
y
++
)
{
...
...
@@ -552,7 +529,7 @@ void make_small(){
}
W
=
maxw
+
2
;
H
=
maxh
+
2
;
cout
<<
"W is "
<<
W
<<
" H is "
<<
H
<<
endl
;
//
cout << "W is " << W << " H is " << H << endl;
return
;
}
...
...
@@ -569,14 +546,14 @@ void make_answer(){
int
line
(){
make_board_str
(
W
,
H
);
std
::
cout
<<
lfsr
<<
std
::
endl
;
//
std::cout << lfsr <<std::endl;
int
status
=
router
(
W
,
H
,
line_num
,
board_str
);
fix_to_board
(
W
,
H
);
if
(
status
){
std
::
cout
<<
"success to line"
<<
std
::
endl
;
//
std::cout << "success to line" << std::endl;
make_answer
();
}
else
{
std
::
cout
<<
"failed to line"
<<
std
::
endl
;
//
std::cout << "failed to line" << std::endl;
}
return
status
;
}
...
...
@@ -632,7 +609,7 @@ int move_mino(int mino,int x, int y){ //1:success 2:failed
break
;
}
}
std
::
cout
<<
"mino "
<<
mino
<<
" can move "
<<
move_x
<<
" "
<<
move_y
<<
std
::
endl
;
//
std::cout << "mino " << mino << " can move " << move_x << " " << move_y << std::endl;
if
(
move_x
!=
0
||
move_y
!=
0
){
mino_x
=
block_data
[
mino
][
0
][
0
];
mino_y
=
block_data
[
mino
][
0
][
1
];
...
...
@@ -682,9 +659,9 @@ int move_along_line(int mino, int l,int dir,int check_num){
if
(
dir
==
1
){
if
(
line_board
[
mino_x
+
block_data
[
mino
][
check_num
][
0
]
-
count
][
mino_y
+
block_data
[
mino
][
check_num
][
1
]]
!=
l
)
break
;
for
(
int
i
=
1
;
i
<=
4
;
i
++
){
cout
<<
i
<<
endl
;
//
cout << i << endl;
if
(
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
<
1
){
cout
<<
"out of grid x "
<<
endl
;
//
cout << "out of grid x " << endl;
flag
=
1
;
break
;
}
...
...
@@ -697,8 +674,8 @@ int move_along_line(int mino, int l,int dir,int check_num){
}
if
(
line_board
[
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
][
mino_y
+
block_data
[
mino
][
i
][
1
]]
==
l
&&
(
line_board
[
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
-
1
][
mino_y
+
block_data
[
mino
][
i
][
1
]]
==
0
||
line_board
[
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
-
1
][
mino_y
+
block_data
[
mino
][
i
][
1
]]
==
l
)
&&
put_data
[
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
-
1
][
mino_y
+
block_data
[
mino
][
i
][
1
]]
==
0
){
//cout <<"continue" << endl;
cout
<<
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
<<
" "
<<
mino_y
+
block_data
[
mino
][
i
][
1
]
<<
" "
<<
line_board
[
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
][
mino_y
+
block_data
[
mino
][
i
][
1
]]
<<
endl
;
cout
<<
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
-
1
<<
" "
<<
mino_y
+
block_data
[
mino
][
i
][
1
]
<<
" "
<<
line_board
[
mino_x
+
block_data
[
mino
][
i
][
0
]
-
count
-
1
][
mino_y
+
block_data
[
mino
][
i
][
1
]]
<<
endl
;
//
cout << mino_x+block_data[mino][i][0]-count << " " << mino_y+block_data[mino][i][1] << " " << line_board[mino_x+block_data[mino][i][0]-count][mino_y+block_data[mino][i][1]] <<endl;
//
cout << mino_x+block_data[mino][i][0]-count-1 << " " << mino_y+block_data[mino][i][1] << " " << line_board[mino_x+block_data[mino][i][0]-count-1][mino_y+block_data[mino][i][1]] <<endl;
//line_board[mino_x+block_data[mino][i][0]-count-1][mino_y+block_data[mino][i][1]]=l;
continue
;
...
...
@@ -743,7 +720,7 @@ int move_along_line(int mino, int l,int dir,int check_num){
}
flag
=
1
;
//cout << "can not move y" << endl;
cout
<<
i
<<
" "
<<
check_num
<<
endl
;
//
cout << i << " " << check_num << endl;
break
;
}
else
{
//cout << "pass" << endl;
...
...
@@ -779,7 +756,7 @@ int set_num(int mino,int line){
int
move2line
(){
vector
<
pair
<
int
,
int
>>
move_order
;
int
move
=
0
,
check_line
=
0
,
mino_dir
,
flag
=
0
,
check_num
=
0
;
std
::
cout
<<
"start move2line"
<<
std
::
endl
;
//
std::cout << "start move2line" << std::endl;
for
(
int
i
=
1
;
i
<=
blocks
;
i
++
){
move_order
.
push_back
(
make_pair
(
block_data
[
i
][
0
][
0
]
+
block_data
[
i
][
0
][
1
],
i
));
}
...
...
@@ -789,7 +766,7 @@ int move2line(){
check_line
=
set_line
(
move_order
[
i
].
second
);
check_num
=
set_num
(
move_order
[
i
].
second
,
check_line
);
if
(
check_line
==
0
)
continue
;
cout
<<
"move "
<<
move_order
[
i
].
second
<<
" line "
<<
check_line
<<
endl
;
//
cout << "move " << move_order[i].second<< " line " <<check_line << endl;
mino_dir
=
move_dir
(
move_order
[
i
].
second
,
check_line
);
flag
=
move_along_line
(
move_order
[
i
].
second
,
check_line
,
mino_dir
,
check_num
);
if
(
flag
){
...
...
@@ -869,13 +846,13 @@ int reshape(){
del_mino_line
(
next
);
while
(
true
){
if
(
move_mino
(
next
,
1
,
1
)){
cout
<<
"moved"
<<
endl
;
//
cout << "moved" << endl;
flag
=
1
;
}
else
{
break
;
}
limit
++
;
cout
<<
limit
<<
endl
;
//
cout << limit << endl;
if
(
limit
>=
end
)
break
;
}
if
(
flag
){
...
...
@@ -917,7 +894,7 @@ void resize(){
}
w
=
maxw
-
minw
+
1
;
h
=
maxh
-
minh
+
1
;
cout
<<
"w is "
<<
w
<<
"h is "
<<
endl
;
//
cout << "w is "<< w << "h is " << endl;
return
;
}
...
...
@@ -994,7 +971,7 @@ void solve(void){
printf
(
"too large
\n
"
);
return
;
}
std
::
cout
<<
"height is "
<<
H
<<
" width is "
<<
W
<<
std
::
endl
;
//
std::cout << "height is " << H <<" width is "<< W << std::endl;
init_mino
();
put_mino
();
...
...
@@ -1013,7 +990,7 @@ void solve(void){
}
}
if
(
check_space
==
0
&&
check_line
==
0
){
cout
<<
"no more reshape"
<<
endl
;
//
cout << "no more reshape" << endl;
}
//resize();
}
...
...
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