voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int a, b, n; cin >> a >> b >> n; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; b += min(tmp, a - 1); } cout << b << endl; } }
B. Jellyfish and Game
大致题意
A 有 $n$ 个苹果,每个都有重量,B 有 $m$ 个,每次交换,A 或者 B 可以选择自己的一个苹果给对方,同时从对方那边拿来一个苹果,两人都希望自己的苹果重量之和最大,问依次交换 $x$ 次后,$A$ 的苹果重量之和是多少
voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); for (auto &i: a) cin >> i; for (auto &i: b) cin >> i; auto sort_all = [&]() { sort(a.begin(), a.end()); sort(b.begin(), b.end()); }; sort_all(); if (a.front() < b.back()) { swap(a.front(), b.back()); } if (k >= 2) { sort_all(); if (b.front() < a.back()) { swap(b.front(), a.back()); } if (k % 2) { sort_all(); if (a.front() < b.back()) { swap(a.front(), b.back()); } } } int tot = 0; for (auto &i : a) tot += i; cout << tot << endl; } }
voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, m; cin >> n >> m; n %= m; if (n == 0) { cout << 0 << endl; continue; } // check m is or not the power of 2 int tmp = gcd(m, n); tmp = m / tmp; bool flag = true; while (tmp != 1) { if (tmp % 2 == 1) { flag = false; break; } tmp >>= 1; } if (!flag) { cout << -1 << endl; continue; }
int ans = n; n <<= 1; while (n) { n %= m; ans += n; n <<= 1; }