当前位置:网站首页>Jscpcp L. collecting diamonds (thinking)
Jscpcp L. collecting diamonds (thinking)
2022-06-11 03:29:00 【to cling】
2022 Jiangsu Collegiate Programming Contest
Solution
- Note that if the operation deletes B Is the current ABC Group cannot continue , And only delete B To change the following ABC Group parity .
- So you should try to delete each group once B, And try to ensure that you delete B Delete as many as possible before AC.
- So a variable is used to store the previous deletion several times B, It can be used to calculate how many can be deleted AC
Code
The nature of the problem is not difficult , The hard part is how to achieve ..
const int N = 2e5 + 5;
pii a[N];
int main()
{
string s; cin >> s;
int n = sz(s);
s = " " + s;
int t = 0;
for (int i = 1; i <= n; i++)
{
if (s[i] != 'B') continue;
int l = i, r = i;
while (l - 1 >= 1 && r + 1 <= n && s[l - 1] == 'A' && s[r + 1] == 'C')
l--, r++;
if(l != r) a[++t] = {
i & 1, i - l };
}
int ans = 0, cnt = 0;// How many times has it been deleted B
for (int i = 1; i <= t; i++)
if (cnt == 0)
{
if (a[i].ft) ans++, cnt++;
else
{
if (a[i].sd == 1) ans++;
else ans += 2, cnt++;
}
}
else
{
ans += min(a[i].sd, (a[i].ft == 0) + cnt + 1);
cnt++;
}
cout << ans << endl;
return 0;
}
边栏推荐
- OpenGL第十一章 多光源
- 计算机视觉(AI)面试大全
- Dépannage du problème de retard des données de communication du micro - ordinateur à puce unique
- js点击太阳月亮切换白天黑夜js特效
- Opencv实现纵横比保持的图像缩放
- The tide play power is really firepower! The first big screen cinema for young people? Cool open TV Max 86 "sudden attack
- Canvas drawing -- how to place the drawing in the center of the canvas
- [cloud native] what is micro service? How to build it? Teach you how to build the first micro service (framework)
- OPENSSL ASN.1, DER, PEM, X509
- Mavros控制无人机在gazebo环境下进行双目SLAM
猜你喜欢

618将至!全渠道开售,高价低配的OPPO Reno6能赢吗?

Shangpinhui mall_ Background homepage of

canvas旋转绘图h5动画js特效

蓄力618 ,苏宁如何打下这场硬仗?

JS click the sun and moon to switch between day and night JS special effect

Checkbox beautify button selected style

Free flying animation of paper plane based on SVG

thinkphp3.2.3反序列化利用链分析

Tweenmax colorful ball bouncing animation

被“内卷”酸翻的OPPO Reno6
随机推荐
词汇表的构建——代码补全快餐教程(3)-分词
Dépannage du problème de retard des données de communication du micro - ordinateur à puce unique
postgresql 捕获函数中的异常
Product milestones in May 2022
亚马逊测评自养号,小白应该如何开始?
canvas交互式星星动画背景js特效
Lvgl Chinese font production
CheckBox美化按钮选中样式
SSL library selection
File file = new file ("test.txt") file path
postgresql 语句
右键 powershell here 功能添加
突破中国品牌创新技术实力,TCL做对了什么?
Disk quota exceeded
Shangpinhui mall_ Background homepage of
单片机通信数据延迟问题排查
用Fragment实现图片简易浏览
OPENSSL ASN. 1, DER, PEM, X509
OpenGL错误指南
正则表达式