2024.12.2 周一
Q1. 1100
给定一个数字(32位以内),使用1,0,-1构造二进制数位,同时保证不能有相邻的非0数存在。
Q2. 1200
给定2个相同数位的数(<=1e100),任意操作:交换2数中相同位的数字使两数之积最大。
Q3. 1300
前缀后缀板题
Q4. 1400
给定n,m(<=2e6)。a:1n,b:1m,问:满足a+b是b*gcd(a,b)倍数的(a,b)对数。
------------------------独自思考分割线------------------------
A1.
发现只需将原本二进制数位中的连续的1替换:1 1 1 0->-1 0 0 1
A2.
发现操作不改变2数之和,则2数之差越小,积则越大。也可直观想象。
操作就是找到最高位不同的数给a,其余每位最大的数给b。
A3.
A4.
数学
------------------------代码分割线------------------------
A1.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<int> res;while (n){res.push_back(n & 1);n >>= 1;}res.push_back(0);n = res.size();for (int i = 0; i < n; i++)if (res[i]){int j = i + 1;for (; j < n && res[j]; j++)res[i] = -1, res[j] = 0;if (j > i + 1) // j位置特判res[j] = 1;i = j - 1;}cout << res.size() << endl;for (auto v : res)cout << v << ' ';cout << endl;
}
A2.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{string a, b;cin >> a >> b;// cout << stoll(a) * stoll(b) << endl;int f = 0;for (int i = 0; i < a.size(); i++)if (!f){if (a[i] - b[i])f = 1;if (a[i] < b[i])swap(a[i], b[i]);}else{if (a[i] > b[i])swap(a[i], b[i]);}cout << a << endl<< b << endl;
}
A3.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n, k;cin >> n >> k;vector<int> a(n + 2), pre(n + 2), repre(n + 2);for (int i = 1; i <= n; i++)cin >> a[i], pre[i] = pre[i - 1] + a[i];for (int i = n; i; i--)repre[i] = repre[i + 1] + a[i];int l, r;for (l = 1; l <= n; l++)if (pre[l] > k - k / 2)break;for (r = n; r; r--)if (repre[r] > k >> 1)break;int res = n - max(0ll, r - l + 1);if (pre[n] <= k)res = n;cout << res << endl;
}
A4.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(6);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n, m;cin >> n >> m;int res = 0;for (int b = 1; b <= m; b++)res += (n + b) / b / b;cout << res - 1 << endl;
}