2024.11.30 周六
1.2025.2.19——15002.11.23 周六3.11.24 周日4.11.25 周一日常5.2024.11.26 周二日常6.2024.11.27 周三7.2024.11.28周四8.2024.11.29 周五
9.2024.11.30 周六
10.2024.12.1 周日11.2024.12.2 周一12.2024.12.3 周二13.2024.12.4 周三14.2024.12.5 周四15.2024.12.7 周六16.2024.12.8 周日17.2024.12.9 周一18.2024.12.10 周二19.2024.12.11 周三20.2024.12.12 周四21.2024.12.13 周五22.2024.12.14 周六23.2024.12.16 周一24.2024.12.17 周二25.2024.12.18 周三26.2024.12.19 周四27.2024.12.20 周五28.2024.12.21 周六29.2024.12.22 周日30.2024.12.23 周一31.2024.12.24 周四32.2024.12.25 周三33.2024.12.26 周四34.2024.12.27 周五35.2024.12.28 周六36.2024.12.29 周日37.2024.12.30 周一38.2025.1.5——120039.2025.1.12——120040.2025.1.14——120041.2025.1.15——120042.2025.1.16——120043.2025.1.17——120044.2025.1.18——130045.2025.1.19——130046.2025.1.20——130047.2025.1.21——130048.2025.1.22——130049.2025.1.24——140050.2025.1.26——140051.2025.2.8——140052.2025.2.9——140053.2025.2.10——140054.2025.2.14——140055.2025.2.15——140056.2025.2.17——14002024.11.30 周六
-
Q1. 1200
给定x(<=107),m(<=1018),循环i:1~m,t=i^x,问t为x或m因子的数量。 -
Q2. 1400
给定n个数,选择四个坐标点组成一个边平行于坐标轴的矩形,问面积最大时选的点。 -
Q3. 1600
给定一数组(非负),在非零数中每次可选一个数(代价本身)/相邻2个数(代价和的2倍)。问最小次数下最小代价。 -
A1. 补:
因子的概念,d为p的因子:d<=p/2,且最高位不同。发现枚举到2倍x或x最高位的下一位即可。其他范围均不会出现x,m的因子。 -
A2. 结论的方式决定代码实现的难度:优化结论
在有解的情况下,结论就是最大值与次小值,次大值与最小值作为边长时最优(推下式子)。 -
A3. 23mins
单个直接选,偶数相邻即可,奇数的话需要扫一遍枚举奇数位,树状数组求两边和的2倍/先求和的2倍再减去单个的O(n)。
- C. n个人,m盘菜,每人有一个期望值,当菜的美味值大于等于期望值时便会端走它,每盘菜从1~n人面前经过。问最后每盘菜的归属。
- 30mins-挺有意思的一道题,前缀数组维护前缀最小值,二分找到第一个小于等于菜的美味值的期望值即归属。
- D. 问所有满足条件的差值大于某值的数列
- 30mins-练爆搜dfs剪枝...
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
const int mod = 998244353;
const int N = 10 + 5e5;
void _();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
_();
return 0;
}
void _()
{
int x, m;
cin >> x >> m;
auto to = [](int x)
{
string s;
while (x)
{
s += to_string(x % 2);
x >>= 1;
}
reverse(s.begin(), s.end());
return s.size();
};
int high_bit = to(x);
int res = 0;
for (int i = 1; i <= min(m, 1ll << high_bit); i++)
{
if (x - i)
{
int t = x ^ i;
if (x % t == 0 || i % t == 0)
{
res++;
}
}
}
cout << res << 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);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
map<int, int> cnt1;
int cnt_2 = 0;
for (int i = 0, x; i < n; i++)
{
cin >> x;
cnt1[x]++;
}
for (auto [c, cnt] : cnt1)
if (cnt > 1)
cnt_2 += cnt >> 1;
if (cnt_2 < 4)
{
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
vector<int> x(4), y(4);
map<int, int> cnt;
vector<int> a;
for (auto [x, ct] : cnt1)
{
int cnt = ct >> 1;
while (cnt--)
a.push_back(x);
}
sort(a.begin(), a.end());
int maxw = a.back(), maxw1 = a[a.size() - 2], minw = a[0], minw1 = a[1];
x[0] = x[1] = minw;
x[2] = x[3] = maxw1;
y[0] = y[2] = minw1;
y[1] = y[3] = maxw;
for (int i = 0; i < 4; i++)
cout << x[i] << ' ' << y[i] << ' ';
cout << endl;
}
// void _()
// {
// int n;
// cin >> n;
// map<int, int> cnt;
// int cnt_2 = 0, cnt_4 = 1e10;
// for (int i = 0, x; i < n; i++)
// {
// cin >> x;
// cnt[x]++;
// if (cnt[x] >= 4)
// cnt_4 = x;
// }
// for (auto [c, cnt] : cnt)
// if (cnt > 1)
// cnt_2 += cnt >> 1;
// if (cnt_2 < 4)
// {
// cout << "NO" << endl;
// return;
// }
// cout << "YES" << endl;
// vector<int> x(4), y(4);
// struct Node
// {
// int x, cnt;
// };
// vector<Node> a;
// for (auto [x, cnt] : cnt)
// if (cnt > 1)
// a.push_back({x, cnt});
// if (a.size() < 4)
// {
// int idx = -1;
// for (int i = 0; i < a.size(); i++)
// if (a[i].cnt > 1 && idx < 4)
// {
// x[++idx] = a[i].x;
// x[++idx] = a[i].x;
// a[i].cnt -= 2;
// }
// idx = -1;
// for (int i = 0; i < a.size(); i++)
// if (a[i].cnt > 1 && idx < 4)
// {
// y[++idx] = a[i].x;
// y[++idx] = a[i].x;
// a[i].cnt -= 2;
// }
// }
// else
// {
// int l1 = 0, l2 = 1, r1 = a.size() - 2, r2 = a.size() - 1;
// x[0] = x[1] = a[l1].x;
// x[2] = x[3] = a[r1].x;
// y[0] = y[2] = a[l2].x;
// y[1] = y[3] = a[r2].x;
// }
// for (int i = 0; i < 4; i++)
// cout << x[i] << ' ' << y[i] << ' ';
// cout << endl;
// }
// void _()
// {
// int n;
// cin >> n;
// map<int, int> cnt;
// int cnt_2 = 0, cnt_4 = 1e10;
// for (int i = 0, x; i < n; i++)
// {
// cin >> x;
// cnt[x]++;
// if (cnt[x] >= 4)
// cnt_4 = x;
// }
// for (auto [c, cnt] : cnt)
// if (cnt > 1)
// cnt_2 += cnt;
// if (cnt_2 < 8)
// {
// cout << "NO" << endl;
// return;
// }
// cout << "YES" << endl;
// vector<int> x(4), y(4);
// if (cnt_4 - (int)1e10)
// {
// // bug(11);
// x = {cnt_4, cnt_4, cnt_4, cnt_4};
// int id = -1;
// cnt[cnt_4] -= 4;
// for (auto &[x, cnt] : cnt)
// while (id < 4 && cnt)
// y[++id] = x, cnt--;
// }
// else
// {
// struct Node
// {
// int x, cnt;
// };
// vector<Node> a;
// for (auto [x, cnt] : cnt)
// a.push_back({x, cnt});
// int l = 0, r = 0;
// int minw = 1e18;
// for (int i = 0; i < a.size() - 1; i++)
// {
// int w = a[i + 1].x - a[i].x;
// if (w < minw)
// {
// w = minw;
// l = i, r = i + 1;
// }
// }
// x[0] = x[1] = a[l].x;
// x[2] = x[3] = a[r].x;
// int l2 = 0, r2 = 0;
// minw = 1e18;
// for (int i = 1; i < a.size() - 1; i++)
// {
// int w = a[i + 1].x - a[i].x;
// if (w < minw && i + 1 - l && i - l && i - r)
// {
// w = minw;
// l2 = i, r2 = i + 1;
// }
// }
// y[0] = y[1] = a[l2].x;
// y[2] = y[3] = a[r2].x;
// }
// for (int i = 0; i < 4; i++)
// cout << x[i] << ' ' << y[i] << ' ';
// cout << 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);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
// 23mins
// 树状数组 快速求前缀和
// 维护差分数组(区间加) 位置(统计个数) ...
struct Tree
{
int n;
vector<int> tr;
Tree(int n1)
{
n = n1 + 2;
tr.assign(n + 2, 0);
}
void add(int x, int c) // 加点
{
for (int i = x; i <= n; i += i & -i)
tr[i] += c;
}
int ask(int x) // 前缀查询
{
int res = 0;
for (int i = x; i; i -= i & -i)
res += tr[i];
return res;
}
int ask(int l, int r) // 区间查询
{
if (l > r)
return 0ll;
return ask(r) - ask(l - 1);
}
}; // Tree tr(n); tr.add(x,c)
void _()
{
int n;
cin >> n;
Tree tr(n);
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i], tr.add(i, a[i]);
int res = 0;
auto get = [&](int l, int r, int mid)
{
return a[mid] + tr.ask(l, mid - 1) * 2 + tr.ask(mid + 1, r) * 2;
};
for (int i = 1; i <= n; i++)
if (a[i])
{
int j = i + 1;
for (; j <= n && a[j]; j++)
;
int l = i, r = j - 1;
// bug2(l, r);
int tres = tr.ask(l, r) << 1;
if ((r - l + 1) & 1)
{
if (r - l + 1 == 1)
tres = a[l];
else
{
for (int k = l; k <= r; k += 2)
tres = min(tres, get(l, r, k));
}
}
i = j - 1;
res += tres;
}
cout << res << endl;
}
C
#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);
int T = 1;
// cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
vector<int> pre(n + 1);
pre[0] = 1e18;
for (int i = 1; i <= n; i++)
cin >> pre[i], pre[i] = min(pre[i], pre[i - 1]); //, bug2(i, pre[i]);
while (m--)
{
int x;
cin >> x;
int l = 0, r = n + 1;
while (r - l - 1)
{
int mid = l + r >> 1;
if (x >= pre[mid])
r = mid;
else
l = mid;
}
if (r > n)
r = -1;
cout << r << endl;
}
}
// void _()
// {
// int n, m;
// cin >> n >> m;
// struct Node
// {
// int x, f;
// };
// vector<Node> a;
// a.push_back({0, 0});
// for (int i = 0; i < n; i++)
// {
// int x;
// cin >> x;
// if (!i)
// a.push_back({x, i + 1});
// else if (x < a[i - 1].x)
// a.push_back({x, i + 1});
// }
// n = a.size();
// while (m--)
// {
// int x;
// cin >> x;
// int l = 0, r = n + 1;
// while (r - l - 1)
// {
// int mid = l + r >> 1;
// if (x >= a[mid].x)
// r = mid;
// else
// l = mid;
// }
// int tans = -1;
// if (r < n)
// tans = a[r].f;
// cout << tans << endl;
// }
// }
D
#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);
int T = 1;
// cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
vector<vector<int>> res;
vector<int> a(n + 1);
function<void(int, int)> dfs = [&](int u, int k)
{
if (k == n)
{
res.push_back(a);
return;
}
for (int i = a[k] + 10; i + (n - k - 1) * 10 <= m; i++)
{
a[k + 1] = i;
dfs(i, k + 1);
}
};
for (int i = 1; i <= m; i++)
{
a[1] = i;
dfs(i, 1);
}
cout << res.size() << endl;
for (auto a : res)
{
for (int i = 1; i <= n; i++)
cout << a[i] << ' ';
cout << endl;
}
}
合集:
日常训练
标签:
codeforces
, 算法竞赛
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!