/*========================================== * (x0,y0)から(x1,y1)へ1歩で移動可能か計算 *------------------------------------------ */ static int can_move(struct map_data *m,int x0,int y0,int x1,int y1,int flag) { if(x1 < 0 || y1 < 0 || x1 >= m->xs || y1 >= m->ys) return 0; if(!can_place(m,x0,y0,flag)) return 0; if(!can_place(m,x1,y1,flag)) return 0; if(x0 == x1 || y0 == y1) return 1; if(!can_place(m,x0,y1,flag) || !can_place(m,x1,y0,flag)) return 0; return 1; }
/*========================================== * (x0,y0)から(x1,y1)へ1歩で移動可能か計算 *------------------------------------------ */ static int can_move(struct map_local *m, int x0, int y0, int x1, int y1) { nullpo_ret(m); if (x0 - x1 < -1 || x0 - x1 > 1 || y0 - y1 < -1 || y0 - y1 > 1) return 0; if (x1 < 0 || y1 < 0 || x1 >= m->xs || y1 >= m->ys) return 0; if (!can_place(m, x0, y0)) return 0; if (!can_place(m, x1, y1)) return 0; if (x0 == x1 || y0 == y1) return 1; if (!can_place(m, x0, y1) || !can_place(m, x1, y0)) return 0; return 1; }
//place a queen in a col of the row void place(int *pos, int row) { int j; for (j = 0; j < N; j++) { if (can_place(pos, row, j)) { pos[row] = j; if (row == N-1) output(pos); else place(pos, row+1); } } }
void dfs(int row) { int i, j; if (row == 8) { _max = _max > val ? _max : val; return; } for (i = 0; i < 8; ++i) if (can_place(row, i)) { prev_pos[row] = i; val += G[row][i]; dfs(row + 1); val -= G[row][i]; } }
Move Game::find_move() { for (int x = 0; x < dimension; x++) { for (int y = 0; y < dimension; y++) { for (int rot = 0; rot < 4; rot++) { for (int i = 0; i < blocks.size(); i++) { block b = blocks[my_number][i]; block bb = rotate_block(b, rot); if (can_place(bb, Point(x, y))) { Move move = {i, rot, x, y}; return move; } } } } } Move move = {0, 0, 0, 0}; return move; }
int main(void) { int i, j; int count = 0; for (i = 0; i < MAP_SIZE; i++) { for (j = 0; j < MAP_SIZE; j++) { scanf("%hhu", &map[i][j]); } } scanf("%hhu", &chess); for (x = 0; x < MAP_SIZE; x++) { for (y = 0; y < MAP_SIZE; y++) { if (can_place() == SUCCESS) { count++; } } } printf("%d\n", count); return 0; }