

文章目录
正文
总共8道题。
1. MC0455 · 四大名著-西游签到
【题目】 MC0455 · 四大名著-西游签到
【AC_Code】
#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e4 + 10; char s[N], t[N];
void solve()
{
int T; cin >> T;
while (T --)
{
cin >> s + 1 >> t + 1;
int l = 1, r = strlen(s + 1);
while (l < r && s[l] == t[l]) l ++;
while (l < r && s[r] == t[r]) r --;
int len = r - l + 1, check = 1;
for (int i = 0; i < len; i ++) if (s[l + i] != t[r - i]) check = 0;
if (check) cout << "Y\n"; else cout << "N\n";
}
}
int main()
{
IOS int _ = 1; // cin >> _;
while (_ --) solve();
return 0;
}
2. MC0456 · 斩断灵藤
【题目】MC0456 · 斩断灵藤
【AC_Code】
#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void solve()
{
int n, m; cin >> n >> m; vector<vector<int>> c(n);
for (int i = 0; i < n - 1; i ++)
{
int u, v; cin >> u >> v; u --; v --;
c[u].push_back(v); c[v].push_back(u);
}
function<int(int, int)> s; int ans = 0;
s = [&](int h, int i)
{
vector<int> k;
for (int l : c[h])
{
if (l == i) continue;
int m = s(l, h); k.push_back(m);
}
sort(k.begin(), k.end());
int a = 1;
for (int p : k)
{
if (a + p > m && p > 0) ans ++;
else if (a + p <= m) a += p;
}
return a;
};
if (s(0, -1) > 0) ans += (1 * 1);
cout << ans << '\n';
}
int main()
{
IOS int _ = 1; // cin >> _;
while (_ --) solve();
return 0;
}
3. MC0457 · 符咒封印
【题目】MC0457 · 符咒封印
【AC_Code】
#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
const int N = 5e5 + 10, mod = 998244353;
ll a[N], b[N], c[N], ans;
void solve()
{
int n, q; cin >> n >> q;
for (int i = 1; i <= n; i ++)
{
cin >> a[i];
b[i] = (b[i - 1] + a[i]) % mod;
c[i] = (c[i - 1] + a[i] * i) % mod;
}
while (q --)
{
int l, r; cin >> l >> r;
ll x = c[r] - c[l - 1], y = b[r] - b[l - 1], z = (l - 1) * y;
ans = (x - z) % mod; ans = (ans + mod) % mod;
cout << ans << '\n';
}
}
int main()
{
IOS int _ = 1; // cin >> _;
while (_ --) solve();
return 0;
}
4. MC0458 · 移铁术
【题目】MC0458 · 移铁术
【AC_Code】
5. MC0459 · 昆仑墟
【题目】MC0459 · 昆仑墟
【AC_Code】
6. MC0460 · 星空迷轨阵
【题目】MC0460 · 星空迷轨阵
【AC_Code】
7. MC0461 · 排队
【题目】MC0461 · 排队
【AC_Code】
#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void solve()
{
int T; cin >> T;
while (T --)
{
int n; cin >> n; vector<int> a[n + 1]; priority_queue<int> q;
for (int i = 1; i <= n; i ++)
{
int opt; cin >> opt; int x, y;
if (opt == 1) { cin >> x; y = n - 1; }
else if (opt == 2) { cin >> y; x = 0; }
else cin >> x >> y;
swap(x, y); x = n - x; y = n - y; a[x].push_back(y);
}
int ans = 1;
for (int i = 1; i <= n; i ++)
{
for (unsigned j = 0; j < a[i].size(); j ++) q.push(-a[i][j]);
if (q.empty()) { ans = 0; break; }
int x = -q.top(); q.pop();
if (x < i) { ans = 0; break; }
}
cout << (ans ? 'Y' : 'N') << '\n';
}
}
int main()
{
IOS int _ = 1; // cin >> _;
while (_ --) solve();
return 0;
}
8. MC0462 · 最后一难
【题目】MC0462 · 最后一难
【AC_Code】
#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
size_t t = 0; int ans = 0;
void solve()
{
string s; cin >> s;
while ((t = s.find("matiji", t)) != string :: npos) { t += 5; ans ++; }
cout << ans << '\n';
}
int main()
{
IOS int _ = 1; // cin >> _;
while (_ --) solve();
return 0;
}
结语
感谢您的阅读!期待您的一键三连!欢迎指正!

1538

被折叠的 条评论
为什么被折叠?



