2024.12.5 周四
给定x2~xn(<=500),构造a1~an,满足i:2~n,x[i]==a[i]%a[i-1]。
n户人家在一条线上,现在在某两户i,i+1之间/两端修建一条公路,给定一01串:0代表希望在公路左边,1则相反。
要求两侧都要有至少一半人家满意。多解则:i尽量距离中间人家最近,如仍多解则选取较小的i。
给定长度为n的数组a和空数组b。二人博弈:Alice选一ai放到b里;Bob选一ai扔掉。
问最优策略下MEX{a}的最大值。
给定n堆石子,二人博弈:每次选定k[1~石子数最少的堆的石子数量],然后将所有非空堆的石子数减少k颗。
最后无法操作者输,问最优策略下胜负。
------------------------独自思考分割线------------------------
-
这次也是比较顺利,除了被Q2卡了一下。确实做这样分段的题还是比较酣畅淋漓的,经过思考能够做出来,不会无效思考,正好锻炼下思维提高思维速度减少所用时间。等思维敏捷顺畅了,再冲高分段的。
A1.
1点:想到对于大数k加上小数b有(k+b)%k==b。
A2.
2点:1.通过前缀快速处理所有合法位置,再进行排序处理。细节搞了好长时间。
2.更妙的做法是可以处理的时候顺便更新答案。除法取整不如翻倍为乘法。
A3.
3点:1.首先应该意识到博弈论不能简单地考虑贪心,应该有个双方最优思维的模拟过程。
2.意识到答案可以二分。
3.最优思维的过程:对于个数大于1个数字无论Bob删除哪个Alice总可以拿到。
则检查x是否可以为答案时,只需要0~x-1数的个数无0,至多1个1即可为答案。
A4.
2点:1.意识到可以排序去重加差分,然后从前向后操作。
2.考虑转折点"攻守易势",即差分后的数组>1,模拟最优策略发现最先到转折点的将一直掌握主动权。
若前n-1个都是1则考虑奇偶性,否则考虑第一个转折点。
------------------------代码分割线------------------------
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;
int res = 1e8;
cout << res << ' ';
for (int i = 2; i <= n; i++)
{
int x;
cin >> x;
res += x;
cout << res << ' ';
}
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 _()
{
int n;
cin >> n;
string s;
cin >> s;
s = " " + s + " ";
vector<int> pre_l0(n + 2), pre_r1(n + 2);
for (int i = 1; i <= n; i++)
pre_l0[i] += pre_l0[i - 1] + (s[i] == '0');
for (int i = n; i; i--)
pre_r1[i] += pre_r1[i + 1] + (s[i] == '1');
int res = -1;
auto d = [&](int x)
{
return abs(n - x * 2);
};
for (int i = 0; i <= n; i++)
if (pre_l0[i] << 1 >= i && pre_r1[i + 1] << 1 >= n - i)
{
// bug(i);
if (d(i) < d(res))
res = i;
}
cout << res << 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;
cin >> n;
map<int, int> cnt;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
cnt[x]++;
}
auto ok = [&](int x)
{
int f = 2;
for (int i = 0; i < x; i++)
if (cnt[i] == 1)
f--;
else if (!cnt[i])
f = 0;
return f > 0;
};
int l = 0, r = n + 10;
while (r - l - 1)
{
int mid = l + r >> 1;
if (ok(mid))
l = mid;
else
r = mid;
}
cout << l << endl;
}
// void _()
// {
// int n;
// cin >> n;
// map<int, int> cnt;
// for (int i = 0; i < n; i++)
// {
// int x;
// cin >> x;
// cnt[x]++;
// }
// for (int i = 0;; i++)
// if (cnt[i] < i + 1)
// {
// cout << i << endl;
// return;
// }
// }
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;
cin >> n;
vector<int> a(n);
for (int &x : a)
cin >> x;
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
for (int i = a.size() - 1; i >= 1; i--)
a[i] -= a[i - 1];
int fir = -1;
for (int i = 0; i < a.size(); i++)
if (a[i] - 1)
{
fir = i + 1;
break;
}
int f = 1;
if (fir + 1 && fir % 2 == 0)
f = 0;
if (fir == -1 && a.size() % 2 == 0)
f = 0;
cout << (f ? "Alice" : "Bob") << endl;
}