Commit ca00a809 authored by makoto.nishizawa's avatar makoto.nishizawa

add README

parent 57afb03f
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
...@@ -73,7 +73,7 @@ int router(short int size_x, short int size_y, short int line_num, short int boa ...@@ -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); lfsr_random_init(seed);
// Step 1 // Step 1
cout << "1st routing ..." << endl; //cout << "1st routing ..." << endl;
for(i = 0; i < line_num; i++) { for(i = 0; i < line_num; i++) {
if(adjacents[i]) continue; if(adjacents[i]) continue;
#ifdef PRINT_SEARCH #ifdef PRINT_SEARCH
...@@ -90,7 +90,7 @@ int router(short int size_x, short int size_y, short int line_num, short int boa ...@@ -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]; ap_uint<1> overlap_checks[MAX_CELLS];
// Step 2 // Step 2
cout << "rip-up routing ..." << endl; //cout << "rip-up routing ..." << endl;
short int last_target = -1; short int last_target = -1;
ap_uint<16> round; ap_uint<16> round;
for(round = 1; round <= ROUND_LIMIT; round++) { for(round = 1; round <= ROUND_LIMIT; round++) {
......
No preview for this file type
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#include"solver.h" #include"solver.h"
#include"io.h" #include"io.h"
#include<stdio.h> #include<stdio.h>
#include <list> //#include <list>
#include <bits/stdc++.h> #include <vector>
#include <algorithm>
//#include <bits/stdc++.h>
#include "router/router.hpp" #include "router/router.hpp"
/* #include<stdlib.h> */ /* #include<stdlib.h> */
/* #include<string.h> */ /* #include<string.h> */
...@@ -38,9 +40,9 @@ void show_blocks(){ ...@@ -38,9 +40,9 @@ void show_blocks(){
int data[4][4]; int data[4][4];
int i,j,k; int i,j,k;
for(i=1;i<blocks;i++){ for(i=1;i<blocks;i++){
printf("block #%d\n",i); //printf("block #%d\n",i);
for(j=1;j<=4;j++){ 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; 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 ...@@ -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){ 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++){ for(int j=0;j<100;j++){
if(check_put_mino(i,x,y,flag)){ if(check_put_mino(i,x,y,flag)){
for(int l=1;l<5;l++){ for(int l=1;l<5;l++){
...@@ -191,13 +193,13 @@ void put_mino(){ ...@@ -191,13 +193,13 @@ void put_mino(){
} }
if(index==-1){ if(index==-1){
for(index=blocks;index>0;index--){ for(index=blocks;index>0;index--){
std::cout << done_block[index]; //std::cout << done_block[index];
if(done_block[index]==0){ if(done_block[index]==0){
next=index; next=index;
break; break;
} }
} }
std::cout << endl; //std::cout << endl;
if(index==0) break; // if all blocks are searched if(index==0) break; // if all blocks are searched
} }
if(index==-1) break; // if all blocks are searched if(index==-1) break; // if all blocks are searched
...@@ -310,7 +312,7 @@ void put_mino(){ ...@@ -310,7 +312,7 @@ void put_mino(){
printf("\n\nstart making order of height\n"); //printf("\n\nstart making order of height\n");
for(int i=1;i<=blocks;i++){//init status for(int i=1;i<=blocks;i++){//init status
check_block[i]=0; check_block[i]=0;
done_block[i]=0; done_block[i]=0;
...@@ -445,7 +447,7 @@ void put_mino(){ ...@@ -445,7 +447,7 @@ void put_mino(){
//if(x==1)break; //if(x==1)break;
}//end of while ture for height }//end of while ture for height
printf("width is \n"); /*printf("width is \n");
for(int i=0;i<order_w.size();i++){ for(int i=0;i<order_w.size();i++){
printf("%d ",order_w[i]); printf("%d ",order_w[i]);
} }
...@@ -456,7 +458,7 @@ void put_mino(){ ...@@ -456,7 +458,7 @@ void put_mino(){
printf("%d ",order_h[i]); printf("%d ",order_h[i]);
} }
printf("\n"); printf("\n");
*/
int put_block[100]; int put_block[100];
int height_c=0,width_c=1; int height_c=0,width_c=1;
int next_put=1; int next_put=1;
...@@ -476,7 +478,7 @@ void put_mino(){ ...@@ -476,7 +478,7 @@ void put_mino(){
max_w = block_data[order_w[j]][k][0]; 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+=max_w+1;
width_c+=SPACE; width_c+=SPACE;
} }
...@@ -490,34 +492,9 @@ void put_mino(){ ...@@ -490,34 +492,9 @@ void put_mino(){
} }
height_c+=max_h+1; height_c+=max_h+1;
} }
print_answer(); //print_answer();
//int next; //int next;
int mino_x,mino_y; 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){ void make_board_str(int size_x,int size_y){
for(int y = 0; y < size_y; y++) { for(int y = 0; y < size_y; y++) {
...@@ -552,7 +529,7 @@ void make_small(){ ...@@ -552,7 +529,7 @@ void make_small(){
} }
W=maxw+2; W=maxw+2;
H=maxh+2; H=maxh+2;
cout << "W is " << W << " H is " << H << endl; //cout << "W is " << W << " H is " << H << endl;
return; return;
} }
...@@ -569,14 +546,14 @@ void make_answer(){ ...@@ -569,14 +546,14 @@ void make_answer(){
int line(){ int line(){
make_board_str(W,H); make_board_str(W,H);
std::cout << lfsr <<std::endl; //std::cout << lfsr <<std::endl;
int status = router(W, H, line_num, board_str); int status = router(W, H, line_num, board_str);
fix_to_board(W,H); fix_to_board(W,H);
if(status){ if(status){
std::cout << "success to line" << std::endl; //std::cout << "success to line" << std::endl;
make_answer(); make_answer();
}else{ }else{
std::cout << "failed to line" << std::endl; //std::cout << "failed to line" << std::endl;
} }
return status; return status;
} }
...@@ -632,7 +609,7 @@ int move_mino(int mino,int x, int y){ //1:success 2:failed ...@@ -632,7 +609,7 @@ int move_mino(int mino,int x, int y){ //1:success 2:failed
break; 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){ if(move_x!=0 || move_y!=0){
mino_x=block_data[mino][0][0]; mino_x=block_data[mino][0][0];
mino_y=block_data[mino][0][1]; mino_y=block_data[mino][0][1];
...@@ -682,9 +659,9 @@ int move_along_line(int mino, int l,int dir,int check_num){ ...@@ -682,9 +659,9 @@ int move_along_line(int mino, int l,int dir,int check_num){
if(dir==1){ 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; 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++){ for(int i=1;i<=4;i++){
cout << i << endl; //cout << i << endl;
if(mino_x+block_data[mino][i][0]-count<1){ if(mino_x+block_data[mino][i][0]-count<1){
cout << "out of grid x " << endl; //cout << "out of grid x " << endl;
flag=1; flag=1;
break; break;
} }
...@@ -697,8 +674,8 @@ int move_along_line(int mino, int l,int dir,int check_num){ ...@@ -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){ 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 <<"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 << " " << 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-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; //line_board[mino_x+block_data[mino][i][0]-count-1][mino_y+block_data[mino][i][1]]=l;
continue; continue;
...@@ -743,7 +720,7 @@ int move_along_line(int mino, int l,int dir,int check_num){ ...@@ -743,7 +720,7 @@ int move_along_line(int mino, int l,int dir,int check_num){
} }
flag=1; flag=1;
//cout << "can not move y" << endl; //cout << "can not move y" << endl;
cout << i << " " << check_num << endl; //cout << i << " " << check_num << endl;
break; break;
}else{ }else{
//cout << "pass" << endl; //cout << "pass" << endl;
...@@ -779,7 +756,7 @@ int set_num(int mino,int line){ ...@@ -779,7 +756,7 @@ int set_num(int mino,int line){
int move2line(){ int move2line(){
vector< pair<int,int>> move_order; vector< pair<int,int>> move_order;
int move=0,check_line=0,mino_dir,flag=0,check_num=0; 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++){ for(int i=1;i<=blocks;i++){
move_order.push_back(make_pair(block_data[i][0][0]+block_data[i][0][1],i)); move_order.push_back(make_pair(block_data[i][0][0]+block_data[i][0][1],i));
} }
...@@ -789,7 +766,7 @@ int move2line(){ ...@@ -789,7 +766,7 @@ int move2line(){
check_line=set_line(move_order[i].second); check_line=set_line(move_order[i].second);
check_num=set_num(move_order[i].second,check_line); check_num=set_num(move_order[i].second,check_line);
if(check_line==0) continue; 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); mino_dir=move_dir(move_order[i].second,check_line);
flag = move_along_line(move_order[i].second, check_line,mino_dir,check_num); flag = move_along_line(move_order[i].second, check_line,mino_dir,check_num);
if(flag){ if(flag){
...@@ -869,13 +846,13 @@ int reshape(){ ...@@ -869,13 +846,13 @@ int reshape(){
del_mino_line(next); del_mino_line(next);
while(true){ while(true){
if(move_mino(next,1,1)){ if(move_mino(next,1,1)){
cout << "moved" << endl; //cout << "moved" << endl;
flag=1; flag=1;
}else{ }else{
break; break;
} }
limit++; limit++;
cout << limit << endl; //cout << limit << endl;
if(limit>=end) break; if(limit>=end) break;
} }
if(flag){ if(flag){
...@@ -917,7 +894,7 @@ void resize(){ ...@@ -917,7 +894,7 @@ void resize(){
} }
w=maxw-minw+1; w=maxw-minw+1;
h=maxh-minh+1; h=maxh-minh+1;
cout << "w is "<< w << "h is " << endl; //cout << "w is "<< w << "h is " << endl;
return; return;
} }
...@@ -994,7 +971,7 @@ void solve(void){ ...@@ -994,7 +971,7 @@ void solve(void){
printf("too large\n"); printf("too large\n");
return; return;
} }
std::cout << "height is " << H <<" width is "<< W << std::endl; //std::cout << "height is " << H <<" width is "<< W << std::endl;
init_mino(); init_mino();
put_mino(); put_mino();
...@@ -1013,7 +990,7 @@ void solve(void){ ...@@ -1013,7 +990,7 @@ void solve(void){
} }
} }
if(check_space==0 && check_line==0){ if(check_space==0 && check_line==0){
cout << "no more reshape" << endl; //cout << "no more reshape" << endl;
} }
//resize(); //resize();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment