当前位置:网站首页>JSCPCP L. Collecting Diamonds(思维)
JSCPCP L. Collecting Diamonds(思维)
2022-06-11 03:21:00 【to cling】
2022 Jiangsu Collegiate Programming Contest
Solution
- 注意到如果操作删除 B 则当前 ABC 组不可能继续操作,并且也只有删除 B 才能更改后面的 ABC 组的奇偶性.
- 所以应该尽量让每个组都操作一次删除 B,并尽量保证在操作删除 B 之前删除尽量多的 AC.
- 所以使用一个变量存储下前面一共删除了几次 B,便可以用以计算可以删除多少个 AC
Code
这道题的性质不难,难的是如何实现。.
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;//前面一共删除了几次 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;
}
边栏推荐
- window10安装keras
- B_ QuRT_ User_ Guide(17)
- Lecturer paging query_ Instructor condition query with page
- 023 MySQL索引优化口诀-索引失效的常见情况
- 配置用命令行编译的环境-MSVC
- 已解决: JDBC连接Mysql失败报错: 'The last packet sent successfully to the server was 0 milliseconds ago. '
- 【安全科普】今天你被社工了吗?
- postgresql 函数的参数为自定义类型时传参格式
- canvas交互式星星动画背景js特效
- svg实现纸飞机自由的飞翔动画
猜你喜欢

ASLR

Tweenmax colorful ball bouncing animation

Troubleshooting of single chip microcomputer communication data delay

Dépannage du problème de retard des données de communication du micro - ordinateur à puce unique

2022 年 5 月产品大事记
![[safety science popularization] have you been accepted by social workers today?](/img/ac/a6d2aa48219d02d82240d2f5343f19.jpg)
[safety science popularization] have you been accepted by social workers today?

HQChart钉钉小程序教程1-创建K线图

{dataSource-1} closing ... {dataSource-1} closed

PIP installation Qt5.

iQOO 8实测上手体验:王者归来,从不高调
随机推荐
js点击太阳月亮切换白天黑夜js特效
postgresql源码学习(十七)—— MVCC②-快照与隔离级别简介
com. mchange. v2.c3p0. Combopooleddatasource red
Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup
SQL | 游戏行业部分指标
【ELT.ZIP】OpenHarmony啃论文俱乐部——数据高通量无损压缩方案
postgresql源码学习(十八)—— MVCC③-创建(获取)快照
删除CSDN上传图片的水印
TweenMax五彩小球弹跳动画
WinDbg-虚拟机-双机调试-驱动文件的调试
ASLR
OPPO K9试水“捆绑销售”,消费者“赚了”还是“亏了”?
Jeecgboot learning_ Online form first experience
Detailed explanation of unity project optimization (continuous supplement)
ROS Basics - use the launch file (I) - start multiple ROS nodes in batch
HikariPool-1 - Shutdown initiated... HikariPool-1 - Shutdown completed.
亚马逊测评自养号,小白应该如何开始?
Pyqt5: basic usage of label control
关于玩家身上有个普通Set并发安全的讨论
Disk quota exceeded