2025.1.20——1300
2025.1.20——1300
A 1300
You are given a binary string
You can perform the following operation on
- choose an integer
such that , then erase the character .
You have to make
Your goal is to calculate two values:
- the minimum number of operations required to make
alternating; - the number of different shortest sequences of operations that make
alternating. Two sequences of operations are different if in at least one operation, the chosen integer is different in these two sequences.
Input
The first line contains one integer
Each test case consists of one line containing the string
Additional constraint on the input:
- the total length of strings
over all test cases does not exceed .
B 1300
You are given two integers
Define a two-dimensional array
For each color from
Input
The first line contains a single integer
The first line of each test case contains two integers
The second line of each test case contains
It is guaranteed that the sum of the values of
C 1300
There is an empty matrix
Zhongkao examination is over, and Daniel would like to do some puzzle games. He is going to fill in the matrix
Define the value of the
You have to help Daniel fill in the matrix
Input
The first line of input contains a single integer
The only line of each test case contains two integers
It is guaranteed that the sum of
D 1300
This is an interactive problem!
salyg1n gave Alice a set
-
Players take turns, with Alice going first.
-
In one move, Alice adds one number
( ) to the set . The set must not contain the number at the time of the move. -
In one move, Bob removes one number
from the set . The set must contain the number at the time of the move. Additionally, the number must be strictly smaller than the last number added by Alice. -
The game ends when Bob cannot make a move or after
moves (in which case Alice's move will be the last one). -
The result of the game is
( at the end of the game). -
Alice aims to maximize the result, while Bob aims to minimize it.
Let
E 1300
Given two arrays
A vertex
A path in a directed graph is a chain of several vertices, connected by edges, such that moving from the vertex
Your task is to find all strong vertices.
For example, if
The graph has only one strong vertex with number
Input
The first line contains an integer
The first line of each test case contains an integer
The second line of each test case contains
The third line of each test case contains
It is guaranteed that the sum of
------------------------思考------------------------
-
方案数/组合数学+发现结论/优化+MEX构造+交互博弈+guess。
A
- 难点在计算方案数,抽象了半天发现通过模拟可以得出计算方法。
B
- 模拟一下发现结论:本质是对 1~k 找到两侧边界开始大于其的第一个位置。
- 前缀维护最大值,二分可以快速回答。 但是考虑 1~k 单调性询问,发现可以双指针解决。
C
- 构造方式比较好想,再计算即可。
D
- 交互。模拟博弈过程,从答案值域和小数据下界入手。发现结论。
E
- 第一眼从样例猜出了答案。细想证明确实比较巧妙。
------------------------代码------------------------
A
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST) \
for (int i = ST; i < VEC.size(); i++) \
cout << VEC[i] << ' '; \
el;
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
constexpr int mod = 998244353;
void _()
{
string s;
cin >> s;
int n = s.size();
s = " " + s;
vector<int> len;
for (int i = 1; i <= n; i++)
{
int j = i;
for (; j <= n && s[j] == s[i]; j++) // j停在的位置为第一个不合法的地方
;
len.push_back(j - i);
i = j - 1;
}
auto get = [](int len)
{
int ans = 1;
for (int i = 1; i <= len; i++)
ans = ans * i % mod;
return ans;
};
int res = 0, f = 1, t = 0;
for (auto len : len)
res += len - 1, f = f * len % mod, t += len - 1;
f = f * get(t) % mod;
cout << res << ' ' << f;
el;
}
B
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST) \
for (int i = ST; i < VEC.size(); i++) \
cout << VEC[i] << ' '; \
el;
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
vector<int> color(k + 1);
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
a[i] = x;
color[x] = 1;
}
int f = 1, g = n;
for (int i = 1; i <= k; i++)
{
if (!color[i])
{
cout << 0 << ' ';
continue;
}
int l = n;
for (;; f++)
if (a[f] >= i)
break;
;
for (;; g--)
if (a[g] >= i)
break;
;
// bug3(i, f, g);
cout << (g - f + 1 << 1) << ' ';
}
el;
}
C
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
vector<vector<int>> f(n + 1, vector<int>(m + 1));
for (int j = 1; j <= m; j++)
f[1][j] = j - 1;
for (int i = 2; i <= min(n, m - 1); i++)
{
f[i][1] = f[i - 1][m];
for (int j = 2; j <= m; j++)
f[i][j] = f[i - 1][j - 1];
}
for (int i = m; i <= n; i++)
for (int j = 1; j <= m; j++)
f[i][j] = f[i - 1][j];
auto MEX = [](vector<int> a)
{
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
for (int i = 0; i < a.size(); i++)
if (a[i] - i)
return i;
return a.back() + 1;
};
vector<int> t;
for (int j = 1; j <= m; j++)
{
vector<int> a;
for (int i = 1; i <= n; i++)
a.push_back(f[i][j]);
t.push_back(MEX(a));
}
// bugv(t, 0);
cout << MEX(t);
el;
for (int i = 1; i <= n; i++)
bugv(f[i], 1);
}
D
#include <bits/stdc++.h>
#define int long long //
// #define endl '\n' // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
map<int, bool> has;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
has[x] = 1;
}
auto f = [](int x)
{
cout << x << endl;
cin >> x;
return x;
};
if (!has[0])
{
f(0);
return;
}
int ans = 0;
for (;; ans++)
if (!has[ans])
break;
int x = f(ans);
while (~x)
x = f(x);
}
E
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
el; \
}
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> f(n);
for (int &x : f)
cin >> x;
int mx = -1e10;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
f[i] -= x;
mx = max(mx, f[i]);
}
int cnt = 0;
vector<int> res;
for (int i = 0; i < n; i++)
if (f[i] == mx)
cnt++, res.push_back(i + 1);
cout << cnt;
el;
bugv(res, 0);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!