Codeforces 451D - Count Good Substrings(组合数学)
来源:互联网 发布:手机ai软件下载 编辑:程序博客网 时间:2024/05/21 17:28
/*题目链接:http://codeforces.com/problemset/problem/451/D题目大意:定义good string,就是就一个字符串的连续相同字符用一个该字符替代后, 形成回文串的字符串。现在给出一个字符串,问说该字符串的子串中, 为good string的串有多少个,分长度为奇数和偶数的输出。因为字符串的组成为a和b,所以只要是头尾相同的子串都是满足的!!!! 所以我们计算在奇数和偶数位置的奇数个数和偶数个数即可, 然后用组合数学求出答案。*/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <cmath>#include <stack>#include <string>#include <sstream>#include <map>#include <set>#define pi acos(-1.0)#define LL long long#define ULL unsigned long long#define inf 0x3f3f3f3f#define INF 1e18#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1using namespace std;typedef pair<int, int> P;const double eps = 1e-10;const int maxn = 1e6 + 5;const int N = 1e4 + 5;const int mod = 1e8;char str[maxn];LL fun(LL a){ return a * (a-1) / 2;}int main(void){//freopen("in.txt","r", stdin); scanf("%s", str+1); LL evenA = 0, oddA = 0; LL evenB = 0, oddB = 0; int len = strlen(str+1); for (int i = 1; i <= len; i++){ if (str[i] == 'a'){ if (i & 1) oddA++; else evenA++; } else { if (i & 1) oddB++; else evenB++; } } LL even = oddA * evenA + oddB * evenB; LL odd = len + fun(oddA) + fun(evenA) + fun(oddB) + fun(evenB); cout << even << " " << odd << endl;return 0;}
0 0
- Codeforces 451D Count Good Substrings(组合数学)
- Codeforces 451D - Count Good Substrings(组合数学)
- Codeforces 451D Count Good Substrings (组合数)
- Codeforces Round #258 (Div. 2) D. 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 #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
- 51 NOD 1091 线段的重叠
- OpenJudge 2989 糖果
- CodeForces 444C - DZY Loves Colors(线段树)
- 树状数组(3)
- ORACLE中使用RAMA删除部分日志
- Codeforces 451D - Count Good Substrings(组合数学)
- hdu 2089 不要62 (数位dp入门)
- 烂泥:VMWare Workation双网卡配置IP地址
- View滑动冲突
- 穷人的真相:从7点忙到23点的上班者,跳出穷人圈子唯一可能是.
- tkinter的进度条scale(尺子)
- HDU 5723 - Abandoned country(最小生成树+dfs)
- 烂泥:wiki系统confluence5.6.6安装、中文、破解及迁移
- 凸优化与对偶问题