百度舆情系统seo技术教程
Problem - 7329 (hdu.edu.cn)
参考:题解 | #1006.Touhou Red Red Blue# 2023杭电暑期多校5
题解:(贪心)
mp['R'], mp['G'], mp['P'] 分别记录对应字母出现过多少次,没有'AAA' or'ABC' 出现时不得分也不进行任何操作,有 'ABC' 出现则扔掉三个字母并自定义两个字母,自定义的两个字母和下一个给定字母组成 'AAA' ,或 mp['R']&&mp['G']&&mp['P'] 每种字母均出现时形成 'AAA',后扔掉 'AAA' 并自定义一个字母,接下来只有两种情况,即 '_AA' or '_AB' 。
注意 i 值的传递
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const ll mod=998244353;
const int inf=1<<30;
const double eps=1e-7;
int T,res,l;
string s;
map<char,int>mp;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
//inline int ABC(int i);
inline int AAA(int i){res++;while(i+1<l){if(s[i]==s[i+1])res++,i+=2;else {if(i+2<l)res++;i+=3;}//return ABC(i+3);}return i+1;
}
//inline int ABC(int i){
// if(i<l)return AAA(i+1);
//}int main(){T=read();while(T--){cin>>s;l=s.length();res=0;mp['R']=mp['G']=mp['B']=0;//mp[s[0]]++;mp[s[1]]++;for(int i=0;i<l;i++){mp[s[i]]++;//printf("start s[%d]%c res:%d R:%d G:%d B:%d\n",i,s[i],res,mp['R'],mp['G'],mp['B']);if(mp['R']&&mp['G']&&mp['B']){//ABCif(i+1<l)i=AAA(i+2);//i=ABC(i+1);//mp['R']=mp['G']=mp['B']=0;//mp[s[i-2]]++;mp[s[i-1]]++;}else if(mp['R']==3||mp['G']==3||mp['B']==3){//AAAi=AAA(i+1);//mp['R']=mp['G']=mp['B']=0;//mp[s[i-2]]++;mp[s[i-1]]++; }/*else{//AABi++;}//printf("s[%d]%c res:%d R:%d G:%d B:%d\n",i,s[i],res,mp['R'],mp['G'],mp['B']);*/}printf("%d\n",res);}return 0;
}