Codeforces 451D Count Good Substrings (组合数)
来源:互联网 发布:擎洲广达软件 培训 编辑:程序博客网 时间:2024/05/22 00:14
题意
给出一个只有a和b的串求有多少个子串满足删去连续的重复字母之后是一个回文串,输出分为奇数长度和偶数长度的。
思路
只有两个字母这是个很重要的条件,这样的话一个子串只需要头和尾相同就可以删成一个回文串了。
那就分别讨论一下就可以了:
代码
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <list>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define LL long long#define lowbit(x) ((x)&(-x))#define lson l, mid, rt << 1#define rson mid + 1, r, rt << 1|1#define MP(a, b) make_pair(a, b)const int INF = 0x3f3f3f3f;const int MOD = 1000000007;const int maxn = 1e5 + 10;const double eps = 1e-8;const double PI = acos(-1.0);typedef pair<int, int> pii;char s[100010];LL cal(LL x){ return x * (x - 1) / 2;}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%s", s + 1); int len = strlen(s + 1); LL odda = 0, oddb = 0; LL evena = 0, evenb = 0; for (int i = 1; i <= len; i++) { if (s[i] == 'a') if (i & 1) odda++; else evena++; else if (i & 1) oddb++; else evenb++; } LL ans1 = cal(odda) + cal(oddb) + cal(evena) + cal(evenb) + len; LL ans2 = odda * evena + oddb * evenb; printf("%lld %lld\n", ans2, ans1); return 0;}
0 0
- Codeforces 451D Count Good Substrings (组合数)
- Codeforces 451D Count Good Substrings(组合数学)
- Codeforces 451D - Count Good Substrings(组合数学)
- Codeforces 451D Count Good Substrings
- codeforces 451D Count Good Substrings 枚举
- Codeforces 451D Count Good Substrings
- 【杂题】 codeforces 451D Count Good Substrings
- Codeforces 451 D. Count Good Substrings
- CodeForces 451D Count Good Substrings
- codeforces 451 D.Count Good Substrings (思维)
- 451 D. Count Good Substrings
- CodeForces 451 D.Count Good Substrings(水~)
- Codeforces Round #258 (Div. 2) D. Count Good Substrings —— 组合数学
- Codeforces #258 (Div. 2) D. Count Good Substrings
- Codeforces Round #258 (Div. 2) D. Count Good Substrings
- Codeforces Round #258 (Div. 2)-D. Count Good Substrings
- codeforces 166 Count Good Substrings 字符串hash
- Codeforces 271D Good Substrings 暴力+Trie
- Android startServer bindServer开始便持久 or 绑定共生死
- 排序算法——快速排序
- Prime Ring Problem——HDU1016
- 机房重构——存储过程
- 442 - Matrix Chain Multiplication
- Codeforces 451D Count Good Substrings (组合数)
- Linux安装Phabricator
- 模块独立性原理
- css样式使用示例
- Android开发实用代码片段(一)
- C--3 (Array, Function
- 【Stanford机器学习笔记】8-Advice for Applying Machine Learning
- 使用selenium+phantomjs模拟登录淘宝
- Interference Signal 第八届