int main(int argc, char *argv[]) { int n, blocks, i; while(scanf("%d%d", &n, &blocks) != EOF) { for(i = 0; i < blocks; i ++) { double x, y; scanf("%lf%lf", &x, &y); putBlock(x, y); } for(i = 0; i < n; i ++) { putBall(); } listNode *tmp = head; double R2 = 0; printf("X\t Y\t R\n"); while (tmp) { if(tmp->isblock) { tmp = tmp->next; continue; } printf("%.3lf\t %.3lf\t %.3lf\t\n",tmp->ball.x, tmp->ball.y, tmp->ball.r); R2 += tmp->ball.r * tmp->ball.r; tmp = tmp->next; } printf("\nsum of R^2: \t%lf\n", R2); freeBox(); } return 0; }
/** * Validates a single tile by checking if there are repetitions in the * tile's row, column or box. This is much faster than checking the entire * board after every move. * * Ignores zero values. */ bool isValidTile(SudokuBoard* board, int col_i, int row_i) { Tile* row = getBoardRow(board, row_i); Tile* col = getBoardColumn(board, col_i); Tile** box = getTileBox(board, col_i, row_i); Tile box_values[BOARD_SIZE]; for (int i = 0; i < BOX_SIZE; i++) { for (int j = 0; j < BOX_SIZE; j++) { box_values[i*BOX_SIZE + j] = box[i][j]; } } bool valid = isValid(row) && isValid(col) && isValid(box_values); free(col); free(row); freeBox(box); return valid; }
/** * Validates whether the board is correct * * A board is incorrect if it has any repetitions */ bool isValidBoard(SudokuBoard* board) { for (int i = 0; i < BOARD_SIZE; i++) { // validate box Tile** box = getBoardBox(board, i); Tile box_values[BOARD_SIZE]; for (int i = 0; i < BOX_SIZE; i++) { for (int j = 0; j < BOX_SIZE; j++) { box_values[i*BOX_SIZE + j] = box[i][j]; } } freeBox(box); if (!isValid(box_values)) { return false; } // validate column Tile* col = getBoardColumn(board, i); bool colValid = isValid(col); free(col); if (!colValid) { return false; } // validate row Tile* row = getBoardRow(board, i); bool rowValid = isValid(row); free(row); if (!rowValid) { return false; } } return true; }
/* Constants in these two functions are fixed empirically for all detections (i.e., the a and b arguments for sigmoid function) */ Real box_pair_score(Box *d1, Box *d2, Flow *fl, Real scale){ Box *forwarded_d = forward_projected_box_scaled(d1, fl, scale); Real distance = box_distance(forwarded_d, d2); freeBox(forwarded_d); return my_log(sigmoid(distance, 50, - 1.0/11)); }