题解:P3677 [CERC2016] 关键的膝盖 Key Knocking
miaoyu2022 · · 题解
考虑形如 "01010101" 的字符串,显然其权值为其长度。
易得若字符串
将输入字符串三个三个分组,则恰分出
长度为
000 -> 011
001 -> 001
010 -> 001
011 -> 011
100 -> 010
101 -> 011
110 -> 101
111 -> 001
没了。
Code:
#include <bits/stdc++.h>
using namespace std;
int n,lst;
char a[300005];
map<string,int> h;
signed main()
{
h["000"]=1;h["001"]=-1;h["010"]=1;h["011"]=-1;h["100"]=0;h["101"]=0;h["110"]=1;h["111"]=0;
scanf("%s",a+1);n=strlen(a+1);
lst=-1;
vector<int> ans;
for(int i=1;i<=n;i+=3)
{
string nw;nw+=a[i];nw+=a[i+1];nw+=a[i+2];
int opt=h[nw];
if(opt!=-1) ans.push_back(i+opt);
}
printf("%d\n",(int)ans.size());
for(auto p:ans) printf("%d ",p);
}