AtCoder Beginner Contest 379
A - Cyclic#
题意#
输入
个连续字符 ,输出另外两种顺序。
思路#
模拟。
代码#
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int mxn = 1e6 + 5;
void solve()
{
char a, b, c;
cin >> a >> b >> c;
cout << b << c << a << endl;
cout << c << a << b << 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 - Strawberries#
题意#
给定长度为
的串 (只包含 ),和 。每次可以消耗连续个 来使答案加 。求答案。
思路#
模拟。
代码#
点击查看代码
#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, k, ans = 0, cnt = 0;
string s;
cin >> n >> k >> s;
for (int i = 0; i < n; i++)
{
if (s[i] == 'X')
{
cnt = 0;
}
else
{
cnt++;
}
if (cnt == k)
{
ans++;
cnt = 0;
}
}
cout << ans << 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 - Sowing Stones#
题意#
个格子,有 个格子有石头。接下来的 行每行 个数据,分别代表石头的位置及数量。每次能将一个石头前移一格(但不能越界)。求使得每个格子恰有一个石头的最小操作数,不可能则输出 。
思路#
假设开始所有石头都在第
格,则需要操作 (等差数列求和)。刨去石头总数多/少了的情况,对于有石头的一格 ,它可以少操 次。
注意:输入不一定是有序的,就是这个让我打出了集训以来最不是人的操作
代码#
点击查看代码
#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, m, sum = 0;
cin >> n >> m;
vector<pii> v(m + 1);
for (int i = 1; i <= m; i++)
{
cin >> v[i].first;
}
for (int i = 1; i <= m; i++)
{
cin >> v[i].second;
sum += v[i].second;
}
if (sum > n)
{
cout << -1 << endl;
return;
}
sort(v.begin(), v.end());
int ans = n * (n + 1) / 2, now = 0;
for (int i = 1; i <= m; i++)
{
if (now < v[i].first - 1)
{
cout << -1 << endl;
return;
}
now += v[i].second;
ans -= v[i].first * v[i].second;
}
cout << ans << 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 - Home Garden#
题意#
个花盆, 次操作,每次操作分 种:
:拿个空花盆种一颗植物,初始高度为 ;
:等 天,现有植物长高 。
:输出高度 及以上的植物的数量,并将这些植物移出花盆。
思路#
由于植物的生长速度一致,所以收获的一定是先种下的植物,用队列来存各个植物种下的时间即可。
代码#
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int mxn = 1e6 + 5;
int tim = 0;
queue<int> q;
void solve()
{
int cmd;
cin >> cmd;
switch (cmd)
{
case 1:
q.push(tim);
break;
case 2:
int t;
cin >> t;
tim += t;
break;
case 3:
{
int h, ans = 0;
cin >> h;
while (q.size() && tim - q.front() >= h)
{
ans++;
q.pop();
}
cout << ans << endl;
}
break;
default:
break;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
E - Sum of All Substrings#
题意#
思路#
对于样例:
代码#
点击查看代码
#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;
cin >> n;
string s, ans;
cin >> s;
vector<int> a(n);
for (int j = 0; j < n; j++)
{
a[j] = (j + 1) * (s[j] - '0');
}
for (int i = 1; i < n; i++)
{
a[i] += a[i - 1];
}
int c = 0;
for (int i = 0; i < n; i++)
{
c += a[n - 1 - i];
ans.push_back('0' + c % 10);
c /= 10;
}
while (c)
{
ans.push_back('0' + c % 10);
c /= 10;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】