EDU74 D 思维题

EDU74 D 思维题

连着n场思维题不会做,脑子有洞吧

题意,非常玄乎。一个串任意一个字符都是一个在一个长度>2的回文串的中,那么这个串是好串,问有多少个好串。。串只包含A/B!!!非常关键感受还是没想到

思路:
没啥思路,枚举右端点,找到规律分类讨论一下就好。规律就是单独出现的字符不在首尾就可以。然而居然当时没发现在想一些奇奇怪怪的做法?
https://codeforces.com/contest/1238/problem/D

#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define PB push_back
#define LL long long
#define pii pair<int,int>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 20
const int inf =0x3f3f3f3f;
const int maxn =4e5+7;

int main(){
    FIO;
    int n;
    LL ans=0;
    string s;
    cin>>n>>s;
    vector<int> a,b;
    for(LL i=0;i<n;i++){
        if(s[i]=='B')swap(a,b);
        if(a.size()==0);
        else if(b.size()==0)ans+=i;
        else ans+=a.back()<b.back()?a.back()+1:i-1;
        a.PB(i);
        if(s[i]=='B')swap(a,b);
    }
    cout<<ans<<endl;

    return 0;
}
/***

***/

猜你喜欢

转载自www.cnblogs.com/zhangxianlong/p/11639185.html