AtCoder Beginner Contest 384
A - aaaadaa#
题意#
给定长为
的字符串 ,和两个字符 、 ,把 中不是 的字符替换成
思路#
模拟
代码#
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int mxn = 1e6 + 5;
void solve()
{
int n;
char a, b;
string s;
cin >> n >> a >> b >> s;
for (int i = 0; i < s.size(); i++)
{
if (s[i] != a)
{
s[i] = b;
}
}
cout << s << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
B - ARC Division#
题意#
场比赛,已知初始分数 ,每场比赛有 与 两个属性,分别表示分区与分数变动。当前分数处在对应分区分数才改变,否则不变。分区 : ,分区 : 。求最终分数
思路#
模拟
代码#
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int mxn = 1e6 + 5;
void solve()
{
int n, r;
cin >> n >> r;
for (int i = 0; i < n; i++)
{
int d, a;
cin >> d >> a;
if (d == 1 && r >= 1600 && r <= 2799)
{
r += a;
}
else if (d == 2 && r >= 1200 && r <= 2399)
{
r += a;
}
}
cout << r << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
C - Perfect Standings#
题意#
总共
个题 ,给定每个题对应的分数 ,输出所有 种出题情况分高的在前,分一样按出题的字典序排。
思路#
求出每种情况的分数,带上字符串排序。
代码#
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, string> pii;
const int mxn = 1e6 + 5;
int a, b, c, d, e;
string s = "ABCDE";
vector<pii> ans;
bool cmp(const pii& a, const pii& b)
{
if (a.first == b.first)
{
return a.second < b.second;
}
return a.first > b.first;
}
void solve()
{
vector<int> SC(5);
for (int i = 0; i < 5; i++)
{
cin >> SC[i];
}
for (int i = 1; i < (1LL << 5); i++) // 每个题都有出跟不出两种情况,没有一个题都没出的情况,所以是<2^5
{
int sc = 0;
string name = "";
for (int j = 0; j < 5; j++)
{
if (i & (1LL << j))
{
name.push_back(s[j]);
sc += SC[j];
}
}
ans.push_back({ sc, name });
}
sort(ans.begin(), ans.end(), cmp);
for (int i = 0; i < ans.size(); i++)
{
cout << ans[i].second << endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
D - Repeated Sequence#
题意#
给定周期为
的无穷序列的前 项,问该无穷序列是否存在连续子序列,使得这个子序列之和等于 。
思路#
因为是连续子序列,很容易想到前缀和,但是这个序列有周期,所以可能出现
(假设周期为 ),所以至少需要 个周期长度的前缀和。并且只需要看 ( 是一个周期之和),即剩下的这部分是否与一个区间和相等即可。由于处理所有区间和需要 的复杂度( 了),所以将 转化为 ,用 来维护,从而简化到
代码#
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n, s;
cin >> n >> s;
vector<int> a(n + 1), pre(2 * (n + 1));
set<int> st;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum += a[i];
pre[i] = pre[i - 1] + a[i];
}
for (int i = n + 1; i <= 2 * n; i++)
{
pre[i] = pre[i - 1] + a[i - n];
}
st.insert(0);
s %= pre[n];
if (!s)
{
cout << "Yes" << endl;
return;
}
for (int i = 1; i <= 2 * n; i++)
{
if (st.count(pre[i] - s))
{
cout << "Yes" << endl;
return;
}
st.insert(pre[i]);
}
cout << "No" << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
E - Takahashi is Slime 2#
题意#
思路#
但需要用小根堆,每次取最小的吸收,当没有可以吸收(队头强度大于等于当前强度)或全部吸收完时结束。
代码#
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int mxn = 5e2 + 5;
struct node
{
int x, y, w;
bool operator < (const node& a)const
{
return w > a.w;
}
};
int h, w, X, a, b, now;
int mp[mxn][mxn];
bool vis[mxn][mxn];
int dx[] = { 1,-1,0,0 };
int dy[] = { 0,0,1,-1 };
void solve()
{
cin >> h >> w >> X >> a >> b;
for (int i = 1; i <= h; i++)
{
for (int j = 1; j <= w; j++)
{
cin >> mp[i][j];
}
}
priority_queue<node> q;
q.push({ a,b,mp[a][b] });
vis[a][b] = true;
bool f = false;
while (q.size())
{
int x = q.top().x;
int y = q.top().y;
if ((int128)mp[x][y] * X >= now&& f) // 注意这里直接乘会爆,要不就int128,要不就直接除也能过
{
break;
}
f = true;
now += q.top().w;
q.pop();
for (int i = 0; i < 4; i++)
{
int tx = x + dx[i];
int ty = y + dy[i];
if (tx > 0 && ty > 0 && tx <= h && ty <= w && !vis[tx][ty])
{
q.push({ tx,ty,mp[tx][ty] });
vis[tx][ty] = true;
}
}
}
cout << now << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效