You need to sign in or sign up before continuing.
Commit ad6fb437 authored by makoto.nishizawa's avatar makoto.nishizawa

made grid

parent d0218176
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
int main(void){ int main(void){
read_problem(); read_problem();
H=20; H=40;
W=20; W=40;
solver(); solver();
print_answer(); print_answer();
......
No preview for this file type
...@@ -109,10 +109,10 @@ void del_mino(int mino){ ...@@ -109,10 +109,10 @@ void del_mino(int mino){
int check_put_mino(int i,int x, int y){// check block#i can put on x,y int check_put_mino(int i,int x, int y){// check block#i can put on x,y
for(int j=1;j<5;j++){ for(int j=1;j<5;j++){
if(x+block_data[i][j][0]>19){ if(x+block_data[i][j][0]>W-1){
return 0; return 0;
} }
if(y+block_data[i][j][1]>19){ if(y+block_data[i][j][1]>H-1){
return 0; return 0;
} }
if(board_data[x+block_data[i][j][0]][y+block_data[i][j][1]]!=0){ if(board_data[x+block_data[i][j][0]][y+block_data[i][j][1]]!=0){
...@@ -127,7 +127,7 @@ int check_put_mino(int i,int x, int y){// check block#i can put on x,y ...@@ -127,7 +127,7 @@ int check_put_mino(int i,int x, int y){// check block#i can put on x,y
void data_mino(int i, int x,int y){ void data_mino(int i, int x,int y){
std::cout << "put mino "<< i << 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)){ if(check_put_mino(i,x,y)){
for(int l=1;l<5;l++){ for(int l=1;l<5;l++){
...@@ -167,22 +167,38 @@ void put_mino(){ ...@@ -167,22 +167,38 @@ void put_mino(){
int index=0; int index=0;
int next=0; int next=0;
int x=0; int x=0;
int another=0;
auto itr=order_w.begin(); auto itr=order_w.begin();
while(true){ while(true){
another=0;
for(index=order_w.size()-1;index>=0;index--){ // find next block for(index=order_w.size()-1;index>=0;index--){ // find next block
if(done_block[order_w[index]]==0){ if(done_block[order_w[index]]==0){
next=order_w[index]; next=order_w[index];
another=1;
//done_block[next]=1; //done_block[next]=1;
//check_block[next]=1; //check_block[next]=1;
break; break;
} }
} }
if(index==-1){
for(index=blocks;index>0;index--){
if(done_block[index]==0){
next=index;
break;
}
}
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
itr=order_w.begin(); if(another){
for(int i=0;i<index;i++){//remove index itretor itr=order_w.begin();
itr++; for(int i=0;i<index;i++){//remove index itretor
itr++;
}
order_w.erase(itr);
}else{
itr=order_w.end();
} }
order_w.erase(itr);
std::cout << "block#"<<next << std::endl; std::cout << "block#"<<next << std::endl;
//make block order //make block order
if(block_data[next][1][0]==block_data[next][2][0]){ if(block_data[next][1][0]==block_data[next][2][0]){
...@@ -290,20 +306,36 @@ void put_mino(){ ...@@ -290,20 +306,36 @@ void put_mino(){
next=0; next=0;
itr=order_h.begin(); itr=order_h.begin();
order_h.push_back(1); order_h.push_back(1);
another=0;
while(true){//start of while true for height while(true){//start of while true for height
another=0;
for(index=order_h.size()-1;index>=0;index--){ // find next block for(index=order_h.size()-1;index>=0;index--){ // find next block
if(done_block[order_h[index]]==0){ if(done_block[order_h[index]]==0){
next=order_h[index]; next=order_h[index];
another=1;
break; break;
} }
} }
if(index==-1){
std::cout << "left block search" << std::endl;
for(index=blocks;index>0;index--){
if(done_block[index]==0){
next=index;
break;
}
}
if(index==0) break; // if all blocks are searched
}
//std::cout << "now" << std::endl; //std::cout << "now" << std::endl;
if(index==-1) break; // if all blocks are searched if(another==1){
itr=order_h.begin(); itr=order_h.begin();
for(int i=0;i<index;i++){//remove index itretor for(int i=0;i<index;i++){//remove index itretor
itr++; itr++;
}
order_h.erase(itr);
}else{
itr=order_h.end();
} }
order_h.erase(itr);
std::cout << "block#"<<next << std::endl; std::cout << "block#"<<next << std::endl;
for(int k=1;k<=4;k++){ for(int k=1;k<=4;k++){
std::cout << block_data[next][k][0]; std::cout << block_data[next][k][0];
...@@ -412,47 +444,34 @@ void put_mino(){ ...@@ -412,47 +444,34 @@ void put_mino(){
printf("\n"); printf("\n");
int put_block[100]; int put_block[100];
int hight_c=1,width_c=1; int height_c=0,width_c=1;
int next_put=1; int next_put=1;
int max_w=0;
int max_h=0;
for(int i=0;i<blocks;i++){ for(int i=0;i<blocks;i++){
hight_c=1; height_c=height_c+SPACE;
width_c=1; width_c=SPACE;
if(i%2){ max_w=0;
for(int j=0;j<blocks;j++){ max_h=0;
if(put_block[order_w[j]]==0){ next_put = order_h[i];
next_put=order_w[j]; for(int j=0;j<blocks;j++){
break; if(order_w[j]==next_put) break;
} for(k=1;k<5;k++){
width_c++; if(block_data[order_w[j]][k][0]>max_w) max_w = block_data[order_w[j]][k][0];
} }
for(int j=0;j<blocks;j++){ //std::cout<< "add " << order_w[j] << " mino " << max_w << std::endl;
if(order_h[j]==next_put){ width_c+=max_w+SPACE;
break; }
} //std::cout << width_c << std::endl;
hight_c++; //std::cout << height_c << std::endl;
} if(max_w==0) data_mino(next_put,width_c,height_c);
data_mino(next_put,width_c,hight_c); else data_mino(next_put,width_c+SPACE,height_c);
mino_order.push_back(next_put); for(int k=1;k<5;k++){
}else{ if(block_data[next_put][k][1]>max_h) max_h = block_data[next_put][k][1];
for(int j=0;j<blocks;j++){
if(put_block[order_h[j]]==0){
next_put=order_h[j];
break;
}
hight_c++;
}
for(int j=0;j<blocks;j++){
if(order_w[j]==next_put){
break;
}
width_c++;
}
data_mino(next_put,width_c,hight_c);
mino_order.push_back(next_put);
} }
put_block[next_put]=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++){ /*for(int i=0;i<blocks;i++){
...@@ -485,7 +504,7 @@ void make_board_str(int size_x,int size_y){ ...@@ -485,7 +504,7 @@ 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++) {
for(int x = 0; x < size_x; x++) { for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x; int idx = y * size_x + x;
board_str[idx] = board_data[y][x]; board_str[idx] = board_data[x][y];
} }
} }
} }
...@@ -493,22 +512,22 @@ void fix_to_board(int size_x, int size_y){ ...@@ -493,22 +512,22 @@ void fix_to_board(int size_x, int size_y){
for(int y = 0; y < size_y; y++) { for(int y = 0; y < size_y; y++) {
for(int x = 0; x < size_x; x++) { for(int x = 0; x < size_x; x++) {
int idx = y * size_x + x; int idx = y * size_x + x;
board_data[y][x] = board_str[idx]; board_data[x][y] = board_str[idx];
} }
} }
} }
void line(){ void line(){
make_board_str(20,20); make_board_str(W,H);
std::cout << lfsr <<std::endl; std::cout << lfsr <<std::endl;
int status = router(20, 20, line_num, board_str); int status = router(W, H, line_num, board_str);
if(status){ if(status){
std::cout << "success to line" << std::endl; std::cout << "success to line" << std::endl;
}else{ }else{
std::cout << "failed to line" << std::endl; std::cout << "failed to line" << std::endl;
} }
fix_to_board(20,20); fix_to_board(W,H);
} }
void solve(void){ void solve(void){
......
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