Codeforces Round #447 (Div. 2) A. QAQ 暴力
来源:互联网 发布:编译c 的软件 编辑:程序博客网 时间:2024/06/06 15:53
题意:
给定字符串,问其中有多少个 “QAQ”,可以不按顺序;
思路:
“A” 是关键点,找到每个“A”构成的 “QAQ”就是答案;
扫字符串,每遇到一个A,他左边的“Q”的个数 * 他右边的“Q”的个数,就是这个“A”组成的个数
#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<set>#include<queue>#include<stack>#include<map>#define PI acos(-1.0)#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)using namespace std;typedef long long ll;typedef unsigned long long ull;const int maxn = 100 + 7, maxd = 670000 + 7, mod = 1e9 + 7;const int INF = 0x7f7f7f7f;int n;char s[maxn];int sum[maxn] = {0};int main() { scanf("%s", s+1); n = strlen(s+1); //cout << n << endl; for(int i = 1; i <= n; ++i) { sum[i] = sum[i-1] + ( s[i] == 'Q' ? 1 : 0 ); } int ans = 0; for(int i = 1; i <= n; ++i) { if(s[i] == 'A') { ans += (sum[i] * (sum[n]-sum[i])); } } cout << ans << endl; return 0;}
阅读全文
1 0
- Codeforces Round #447 (Div. 2) A. QAQ 暴力
- Codeforces Round #447 A. QAQ
- Codeforces Round #329 (Div. 2) A. 2Char 字符串+暴力
- Codeforces Round #243 (Div. 2) A,B,C(暴力枚举)
- Codeforces Round #271 (Div. 2) --A Keyboard (暴力)
- Codeforces Round #283 (Div. 2)---A. Minimum Difficulty (暴力)
- Codeforces Round #286 (Div. 2) A.(回文串暴力)
- Codeforces Round #281 (Div. 2)A(构造+暴力模拟)
- Codeforces Round #344 (Div. 2) A 题题解 (暴力)
- Codeforces Round #354 (Div. 2)(A)暴力,模拟
- Codeforces Round #387(Div. 2)A. Display Size【暴力】
- Codeforces Round #396 (Div. 2) A---C 暴力+dp
- Codeforces Round #433 (Div. 2) A.Fraction(暴力)
- Codeforces Round#447 Div2 QAQ
- Codeforces Round #336 (Div. 2) B 暴力
- Codeforces Round #309 (Div. 2) B 暴力
- Codeforces Round #363 (Div. 2) B 暴力
- Codeforces Round #279 (Div. 2) D 暴力
- HDUOJ 1025
- bos项目day04区域条件查询:报错ERROR DefaultDispatcherErrorHandler:42
- 入门Webpack
- [Tensorflow]L2正则化和collection【tf.GraphKeys】
- 面向对象思想的理解
- Codeforces Round #447 (Div. 2) A. QAQ 暴力
- addPeer操作解析
- 无监督特征学习基本原理
- (转)区块链:CITA
- 学生排队
- 推箱子
- erlang gen_fsm源码分析
- Selenium--显示等待和隐式等待
- C语言操作符的介绍及总结