版本比较
A+B冷门解法
正文
增加 60 行删除 60 行
1233456784 行未改动92939495969697989899100101102102103104105105106107108109183 行未改动全部展开29329429529629729729829930030113 行未改动31531631731831931932032132232395 行未改动41942042142242342342442542642717 行未改动4454464474484494494504514514524534544554564574584584594604614624634634644654664674684684694704714724734744754764774774784794804813 行未改动485486487488489489490491492492493494495495496497498499119 行未改动全部展开61962062162262362362462562662762762862963063063163263263363463563658 行未改动6956966976986996997007017027037047057067067077087097107117127137147127137147157167167177187197197207217217227237247253 行未改动729730731732733734735736737738733734735736737738739740741742147 行未改动全部展开89089189289389489489589689789868 行未改动96796896997097197197297397497510 行未改动9869879889899909909919929939939949959959969979979989991000100160 行未改动106210631064106510661067106810691066106710681069107010711072107310741075107610771078107810791080108110821083108310841085108610871087108810891090109110921092109310941095109510961097109810991100110111021102110311041105110611071107110811091110111111111112111311141115111511161117111811181119112011211122112311231124112511261127112711281129113011311132113311331134113511361136113711381138113911401141## 前言
你说什么?问我为什么要写这依托东西?就是纯闲的 你说什么?问我为什么要写这依托东西?就是纯闲的
此处给出了题解区的没提到过的做法,而且亲测每种做法都能过,不能过的话踢我()
84 行未改动}
int main() { int a = read(), b = read();
odt.insert(Node(0, 1e9, 0));
assign(0, 0, a); assign(1, 1, b); assign(0, 1, a + b);
auto it = odt.lower_bound(Node(0)); out(it->v);
return 0;}```
183 行未改动全部展开
struct Matrix { int a, b, c, d; Matrix(int a = 1, int b = 0, int c = 0, int d = 1) : a(a), b(b), c(c), d(d) {}
inline Matrix operator*(const Matrix &other) const { return Matrix( a * other.a + b * other.c, a * other.b + b * other.d,13 行未改动 int dp1 = MA.a * dp0 + MA.b * one; int dp2 = MB.a * dp1 + MB.b * one;
out(dp2);
return 0;}```
95 行未改动
int rebuild(int l, int r, int dim) { if (l > r) return 0; int mid = (l + r) >> 1, u = new_node(); nth_element(pt + l, pt + mid, pt + r + 1, nth_element(pt + l, pt + mid, pt + r + 1, [dim](const Point &a, const Point &b) { return a.x[dim] < b.x[dim]; }); tr[u].p = pt[mid];17 行未改动 tr[u].p = p; push_up(u); return; } if (p.x[dim] <= tr[u].p.x[dim]) if (p.x[dim] <= tr[u].p.x[dim]) insert(tr[u].l, p, dim ^ 1); else else insert(tr[u].r, p, dim ^ 1); push_up(u); maintain(u, dim);}
inline bool in_range(const Node &t, int x1, int y1, int x2, int y2) { return t.L[0] >= x1 && t.R[0] <= x2 && return t.L[0] >= x1 && t.R[0] <= x2 && t.L[1] >= y1 && t.R[1] <= y2;}
inline bool point_in(const Point &t, int x1, int y1, int x2, int y2) { return t.x[0] >= x1 && t.x[0] <= x2 && return t.x[0] >= x1 && t.x[0] <= x2 && t.x[1] >= y1 && t.x[1] <= y2;}
inline bool out_range(const Node &t, int x1, int y1, int x2, int y2) { return t.R[0] < x1 || t.L[0] > x2 || return t.R[0] < x1 || t.L[0] > x2 || t.R[1] < y1 || t.L[1] > y2;}
int query(int u, int x1, int y1, int x2, int y2) { if (!u) return 0; if (in_range(tr[u], x1, y1, x2, y2)) return tr[u].sum; if (out_range(tr[u], x1, y1, x2, y2)) return 0; int res = 0; if (point_in(tr[u].p, x1, y1, x2, y2)) if (point_in(tr[u].p, x1, y1, x2, y2)) res += tr[u].p.w; res += query(tr[u].l, x1, y1, x2, y2); res += query(tr[u].r, x1, y1, x2, y2); return res;3 行未改动 tr[0].L[0] = tr[0].L[1] = INF; tr[0].R[0] = tr[0].R[1] = -INF;
int a = read(), b = read();
insert(rt, {a, 0, a}, 0); insert(rt, {0, b, b}, 0);
int sum = query(rt, -INF, -INF, INF, INF); out(sum);
return 0;}```
119 行未改动全部展开}
int main() { int a = read(), b = read();
vector<Point> points; points.emplace_back(a, 0); points.emplace_back(-b, 0);
int minDistSq = closestPair(points); int sum = sqrt(minDistSq);
out(sum);
return 0;}```
58 行未改动
inline double calc(const function<double(double)>& f, double a, double b, int n = 1000) { double h = (b - a) / n; double sum = f(a) + f(b);
for (int i = 1; i < n; i += 2) { sum += 4.0 * f(a + i * h); } for (int i = 2; i < n; i += 2) { sum += 2.0 * f(a + i * h); }
return sum * h / 3.0;}
int main() { int a = read(), b = read(); auto func = [a, b](double x) { return static_cast<double>(a + b);
auto func = [a, b](double x) { return static_cast<double>(a + b); };
double res = calc(func, 0.0, 1.0); int rres = static_cast<int>(round(res));
out(rres);
return 0;}```
3 行未改动设变量为x和y,表示a和b的值。我们需要最大化x+y,同时约束x=a和y=b。
将A+B问题建模为线性规划:
最大化 x + y 约束: x = a, y = b 转换为标准形式: 最大化 x + y 约束: x ≤ a, -x ≤ -a y ≤ b, -y ≤ -b 最大化 x + y约束: x = a, y = b转换为标准形式:最大化 x + y约束: x ≤ a, -x ≤ -a y ≤ b, -y ≤ -b
代码如下:``` cpp// Ciallo~(∠・ω< )⌒★147 行未改动全部展开 {0.0, 1.0}, // y ≤ b {0.0, -1.0} // -y ≤ -b };
vector<double> B = {static_cast<double>(a), static_cast<double>(-a), vector<double> B = {static_cast<double>(a), static_cast<double>(-a), static_cast<double>(b), static_cast<double>(-b)}; vector<double> C = {1.0, 1.0};
SimplexSolver solver(A, B, C);68 行未改动#define debug(x) cout << #x << " = " << (x) << endl
class GeFunc {private: vi vec; vi vec;public: explicit GeFunc(int value = 0) { vec.push_back(value); }10 行未改动};
int main() { int a = read(), b = read();
GeFunc gf1(a); GeFunc gf2(b);
GeFunc sum = gf1 + gf2;
out(sum.get());
return 0;}```
60 行未改动#define lowbit(x) ((x) & (-(x)))#define debug(x) cout << #x << " = " << (x) << endl
struct DCTNode { int l, r; int val; bool is; DCTNode *left, *right; int l, r; int val; bool is; DCTNode *left, *right; DCTNode(int l, int r, int val, bool is) : l(l), r(r), val(val), is(is), left(nullptr), right(nullptr) {}};
class DecompositionTree {private: DCTNode* root; vi data;
DCTNode* build(int l, int r) { if (l == r) { return new DCTNode(l, r, data[l], false); }
int mid = (l + r) >> 1; DCTNode* left = build(l, mid); DCTNode* right = build(mid + 1, r);
int sum = left->val + right->val; DCTNode* node = new DCTNode(l, r, sum, true); node->left = left; node->right = right;
return node; }
void destroy(DCTNode* node) { if (!node) return; destroy(node->left); destroy(node->right); delete node; }
public: explicit DecompositionTree(const vi& arr) : data(arr) { root = arr.empty() ? nullptr : build(0, (int)arr.size() - 1); }
~DecompositionTree() { destroy(root); }
inline int get_sum() const { return root ? root->val : 0; }
void print_tr(DCTNode* node, int indent = 0) const { if (!node) return;
for (int i = 0; i < indent; ++i) putchar(' '); printf("[%d,%d]: %d", node->l, node->r, node->val); if (node->is) printf(" (Merge)"); putchar('\n');
print_tr(node->left, indent + 4); print_tr(node->right, indent + 4); }
inline DCTNode* get_root() const { return root; }};
int main() { int a = read(), b = read();
vi arr = {a, b}; DecompositionTree dt(arr);
out(dt.get_sum());
return 0;}```