题目大意:定义一个串的价值为相邻不同的个数 + 1 +1 +1,给定一个长度为 3 n 3n 3n的字符串,要求通过最多 n n n次操作,使得串的价值至少为 2 n 2n 2n。操作反转两个相邻元素:将 [ x ] , [ x + 1 ] [x],[x+1] [x],[x+1]两个元素的值反转, 0 → 1 , 1 → 0 0 \rightarrow 1,1 \rightarrow 0 0→1,1→0.
思路:每 3 3 3个字符执行一次分割,只要能把每组分成 2 2 2段而且和前面的不相连,最后段数一定不小于 2 n 2n 2n。因此首先判断前一个字符,然后根据前一个字符枚举当前 3 3 3个字符的状态,共 16 16 16种状态,去除已经分好不需要操作的状态共 8 8 8种状态。
bef = 0
000
001
011
111
bef = 1
000
100
110
111
分别计数判断即可。
#include
using namespace std;
int ans[5000010], cnt = 0;
inline void solve(){
string str; cin >> str;
int n = str.length();
str = ' ' + str;
for(int i = 1; i + 2
关注
打赏
- 回坑记之或许是退役赛季?
- [LCT刷题] P1501 [国家集训队]Tree II
- [LCT刷题] P2147 洞穴勘测
- 2022-2023 ICPC Brazil Subregional Programming Contest VP记录
- [线段树套单调栈] 2019-2020 ICPC Asia Hong Kong Regional Contest H.[Hold the Line]
- The 2021 ICPC Asia Nanjing Regional Contest E.Paimon Segment Tree 区间合并线段树/维护矩阵乘法
- CF580E - Kefa and Watch 线段树维护哈希
- HDU5869 Different GCD Subarray Query 离线查询/区间贡献
- 27.CF1004F Sonya and Bitwise OR 区间合并线段树
- 26.CF1000F One Occurrence