A. QAQ
A. QAQ
法1
由于数据范围比较小,可以三层循环求解
法2
每一个A的下标存到数组v中,开个cnt数组记录每个位置前面有多少个'Q',利用前缀和可以求得范围内'Q'的数量
点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std;
#define X first
#define Y second
typedef pair<int,int> pii;
typedef long long LL;
const char nl = '\n';
const int N = 110;
const int M = 2e5+10;
int n,m;
int cnt[N];
void solve(){
string s;
cin >> s;
n = s.size();
vector<int> v;
for(int i = 0; i < n; i ++ ){
if(s[i] == 'Q')cnt[i + 1] ++;
else if(s[i] == 'A')v.push_back(i + 1);
cnt[i + 1] += cnt[i];
}
LL ans = 0;
for(auto x:v){
ans += cnt[x - 1] * (cnt[n] - cnt[x]);
}
cout << ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
solve();
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】