boolean LineObj::Intersects (LineObj& l) { // from Sedgewick, p. 313 BoxObj b1 (_p1._x, _p1._y, _p2._x, _p2._y); BoxObj b2 (l._p1._x, l._p1._y, l._p2._x, l._p2._y); return b1.Intersects(b2) && Same(l._p1, l._p2) <= 0 && l.Same(_p1, _p2) <= 0; }
void RegressionTree::Fit(DataVector *data, size_t len, Node *node, size_t depth, double *gain) { size_t max_depth = g_conf.max_depth; if (g_conf.loss == SQUARED_ERROR) { node->pred = Average(*data, len); } else if (g_conf.loss == LOG_LIKELIHOOD) { node->pred = LogitOptimalValue(*data, len); } if (max_depth == depth || Same(*data, len) || len <= g_conf.min_leaf_size) { node->leaf = true; return; } double g = 0.0; if (!FindSplit(data, len, &(node->index), &(node->value), &g)) { node->leaf = true; return; } DataVector out[Node::CHILDSIZE]; SplitData(*data, len, node->index, node->value, out); if (out[Node::LT].empty() || out[Node::GE].empty()) { node->leaf = true; return; } // update gain if (gain[node->index] < g) { gain[node->index] = g; } // increase feature cost if certain feature is used if (g_conf.feature_costs && g_conf.enable_feature_tunning) { g_conf.feature_costs[node->index] += 1.0e-4; } node->child[Node::LT] = new Node(); node->child[Node::GE] = new Node(); Fit(&out[Node::LT], node->child[Node::LT], depth+1, gain); Fit(&out[Node::GE], node->child[Node::GE], depth+1, gain); if (!out[Node::UNKNOWN].empty()) { node->child[Node::UNKNOWN] = new Node(); Fit(&out[Node::UNKNOWN], node->child[Node::UNKNOWN], depth+1, gain); } }
int main(){ freopen("combo.in", "r", stdin); freopen("combo.out", "w", stdout); scanf("%d", &total_number); for(int i = 0; i < 2; ++i) for(int j = 0; j < 3; ++j) scanf("%d", &password[i][j]); for(int i = 0; i < 3; ++i) diff[i] = Same(password[0][i], password[1][i]); int possibility = MIN(5, total_number); printf("%d\n", 2 * possibility * possibility * possibility - diff[0] * diff[1] * diff[2]); return 0; }
// ---------------------------------------------------- Exit* Room::GetExit(const string& direction) const { for(list<Entity*>::const_iterator it = container.begin(); it != container.cend(); ++it) { if((*it)->type == EXIT) { Exit* ex = (Exit*) *it; if(Same(ex->GetNameFrom(this), direction)) return ex; } } return NULL; }