Loading main.cpp +2 −2 Changes for main.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -5,8 +5,8 @@ int main(void){ read_problem(); H=20; W=20; H=40; W=40; solver(); print_answer(); Loading solve −216 B (112 KiB) File changed.No diff preview for this file type. View original file View changed file solver.cpp +61 −42 Changes for solver.cpp: 61 added lines, 42 removed lines. Original line number Diff line number Diff line Loading @@ -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 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; } if(y+block_data[i][j][1]>19){ if(y+block_data[i][j][1]>H-1){ return 0; } if(board_data[x+block_data[i][j][0]][y+block_data[i][j][1]]!=0){ Loading @@ -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){ std::cout << "put mino "<< i << 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)){ for(int l=1;l<5;l++){ Loading Loading @@ -167,22 +167,38 @@ void put_mino(){ int index=0; int next=0; int x=0; int another=0; auto itr=order_w.begin(); while(true){ another=0; for(index=order_w.size()-1;index>=0;index--){ // find next block if(done_block[order_w[index]]==0){ next=order_w[index]; another=1; //done_block[next]=1; //check_block[next]=1; 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(another){ itr=order_w.begin(); for(int i=0;i<index;i++){//remove index itretor itr++; } order_w.erase(itr); }else{ itr=order_w.end(); } std::cout << "block#"<<next << std::endl; //make block order if(block_data[next][1][0]==block_data[next][2][0]){ Loading Loading @@ -290,20 +306,36 @@ void put_mino(){ next=0; itr=order_h.begin(); order_h.push_back(1); another=0; while(true){//start of while true for height another=0; for(index=order_h.size()-1;index>=0;index--){ // find next block if(done_block[order_h[index]]==0){ next=order_h[index]; another=1; 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; if(index==-1) break; // if all blocks are searched if(another==1){ itr=order_h.begin(); for(int i=0;i<index;i++){//remove index itretor itr++; } order_h.erase(itr); }else{ itr=order_h.end(); } std::cout << "block#"<<next << std::endl; for(int k=1;k<=4;k++){ std::cout << block_data[next][k][0]; Loading Loading @@ -412,47 +444,34 @@ void put_mino(){ printf("\n"); int put_block[100]; int hight_c=1,width_c=1; int height_c=0,width_c=1; int next_put=1; int max_w=0; int max_h=0; for(int i=0;i<blocks;i++){ hight_c=1; width_c=1; if(i%2){ height_c=height_c+SPACE; width_c=SPACE; max_w=0; max_h=0; next_put = order_h[i]; for(int j=0;j<blocks;j++){ if(put_block[order_w[j]]==0){ next_put=order_w[j]; break; } width_c++; } for(int j=0;j<blocks;j++){ if(order_h[j]==next_put){ break; } hight_c++; } data_mino(next_put,width_c,hight_c); mino_order.push_back(next_put); }else{ for(int j=0;j<blocks;j++){ if(put_block[order_h[j]]==0){ next_put=order_h[j]; break; if(order_w[j]==next_put) break; for(k=1;k<5;k++){ if(block_data[order_w[j]][k][0]>max_w) max_w = block_data[order_w[j]][k][0]; } hight_c++; //std::cout<< "add " << order_w[j] << " mino " << max_w << std::endl; width_c+=max_w+SPACE; } for(int j=0;j<blocks;j++){ if(order_w[j]==next_put){ break; } width_c++; //std::cout << width_c << std::endl; //std::cout << height_c << std::endl; if(max_w==0) data_mino(next_put,width_c,height_c); else data_mino(next_put,width_c+SPACE,height_c); for(int k=1;k<5;k++){ if(block_data[next_put][k][1]>max_h) max_h = block_data[next_put][k][1]; } data_mino(next_put,width_c,hight_c); mino_order.push_back(next_put); height_c+=max_h+1; } put_block[next_put]=1; print_answer(); } //int next; int mino_x,mino_y; /*for(int i=0;i<blocks;i++){ Loading Loading @@ -485,7 +504,7 @@ void make_board_str(int size_x,int size_y){ for(int y = 0; y < size_y; y++) { for(int x = 0; x < size_x; x++) { int idx = y * size_x + x; board_str[idx] = board_data[y][x]; board_str[idx] = board_data[x][y]; } } } Loading @@ -493,22 +512,22 @@ void fix_to_board(int size_x, int size_y){ for(int y = 0; y < size_y; y++) { for(int x = 0; x < 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(){ make_board_str(20,20); make_board_str(W,H); 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){ std::cout << "success to line" << std::endl; }else{ std::cout << "failed to line" << std::endl; } fix_to_board(20,20); fix_to_board(W,H); } void solve(void){ Loading Loading
main.cpp +2 −2 Changes for main.cpp: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -5,8 +5,8 @@ int main(void){ read_problem(); H=20; W=20; H=40; W=40; solver(); print_answer(); Loading
solve −216 B (112 KiB) File changed.No diff preview for this file type. View original file View changed file
solver.cpp +61 −42 Changes for solver.cpp: 61 added lines, 42 removed lines. Original line number Diff line number Diff line Loading @@ -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 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; } if(y+block_data[i][j][1]>19){ if(y+block_data[i][j][1]>H-1){ return 0; } if(board_data[x+block_data[i][j][0]][y+block_data[i][j][1]]!=0){ Loading @@ -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){ std::cout << "put mino "<< i << 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)){ for(int l=1;l<5;l++){ Loading Loading @@ -167,22 +167,38 @@ void put_mino(){ int index=0; int next=0; int x=0; int another=0; auto itr=order_w.begin(); while(true){ another=0; for(index=order_w.size()-1;index>=0;index--){ // find next block if(done_block[order_w[index]]==0){ next=order_w[index]; another=1; //done_block[next]=1; //check_block[next]=1; 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(another){ itr=order_w.begin(); for(int i=0;i<index;i++){//remove index itretor itr++; } order_w.erase(itr); }else{ itr=order_w.end(); } std::cout << "block#"<<next << std::endl; //make block order if(block_data[next][1][0]==block_data[next][2][0]){ Loading Loading @@ -290,20 +306,36 @@ void put_mino(){ next=0; itr=order_h.begin(); order_h.push_back(1); another=0; while(true){//start of while true for height another=0; for(index=order_h.size()-1;index>=0;index--){ // find next block if(done_block[order_h[index]]==0){ next=order_h[index]; another=1; 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; if(index==-1) break; // if all blocks are searched if(another==1){ itr=order_h.begin(); for(int i=0;i<index;i++){//remove index itretor itr++; } order_h.erase(itr); }else{ itr=order_h.end(); } std::cout << "block#"<<next << std::endl; for(int k=1;k<=4;k++){ std::cout << block_data[next][k][0]; Loading Loading @@ -412,47 +444,34 @@ void put_mino(){ printf("\n"); int put_block[100]; int hight_c=1,width_c=1; int height_c=0,width_c=1; int next_put=1; int max_w=0; int max_h=0; for(int i=0;i<blocks;i++){ hight_c=1; width_c=1; if(i%2){ height_c=height_c+SPACE; width_c=SPACE; max_w=0; max_h=0; next_put = order_h[i]; for(int j=0;j<blocks;j++){ if(put_block[order_w[j]]==0){ next_put=order_w[j]; break; } width_c++; } for(int j=0;j<blocks;j++){ if(order_h[j]==next_put){ break; } hight_c++; } data_mino(next_put,width_c,hight_c); mino_order.push_back(next_put); }else{ for(int j=0;j<blocks;j++){ if(put_block[order_h[j]]==0){ next_put=order_h[j]; break; if(order_w[j]==next_put) break; for(k=1;k<5;k++){ if(block_data[order_w[j]][k][0]>max_w) max_w = block_data[order_w[j]][k][0]; } hight_c++; //std::cout<< "add " << order_w[j] << " mino " << max_w << std::endl; width_c+=max_w+SPACE; } for(int j=0;j<blocks;j++){ if(order_w[j]==next_put){ break; } width_c++; //std::cout << width_c << std::endl; //std::cout << height_c << std::endl; if(max_w==0) data_mino(next_put,width_c,height_c); else data_mino(next_put,width_c+SPACE,height_c); for(int k=1;k<5;k++){ if(block_data[next_put][k][1]>max_h) max_h = block_data[next_put][k][1]; } data_mino(next_put,width_c,hight_c); mino_order.push_back(next_put); height_c+=max_h+1; } put_block[next_put]=1; print_answer(); } //int next; int mino_x,mino_y; /*for(int i=0;i<blocks;i++){ Loading Loading @@ -485,7 +504,7 @@ void make_board_str(int size_x,int size_y){ for(int y = 0; y < size_y; y++) { for(int x = 0; x < size_x; x++) { int idx = y * size_x + x; board_str[idx] = board_data[y][x]; board_str[idx] = board_data[x][y]; } } } Loading @@ -493,22 +512,22 @@ void fix_to_board(int size_x, int size_y){ for(int y = 0; y < size_y; y++) { for(int x = 0; x < 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(){ make_board_str(20,20); make_board_str(W,H); 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){ std::cout << "success to line" << std::endl; }else{ std::cout << "failed to line" << std::endl; } fix_to_board(20,20); fix_to_board(W,H); } void solve(void){ Loading