您的位置:首页 > 编程语言 > Go语言

【杂题】 codeforces 451D Count Good Substrings

2014-07-25 16:45 204 查看
一道数学题。。。刚开始看以为是后缀数组。。。然后用后缀数组做啊做啊。。调啊调啊。。。晕晕,后来发现题目中只有a和b。。。晕晕。。就挨个加与它之前相同字符且奇偶和它不同的就行了。。。晕晕。。

#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 100005
#define eps 1e-10
#define mod 1000000009
#define INF 99999999
#define lowbit(x) (x&(-x))
//#define lson o<<1, L, mid
//#define rson o<<1 | 1, mid+1, R
typedef long long LL;
//typedef int LL;
using namespace std;

int pre[3][3];
char s[maxn];
int main(void)
{
scanf("%s", s);
int len = strlen(s);
LL even = 0, odd = 0;
for(int i = 0; i < len; i++) {
int tmp = s[i] - 'a';
pre[tmp][i%2]++;
even += pre[tmp][(i%2)^1];
odd += pre[tmp][i%2];
}
printf("%I64d %I64d\n", even, odd);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: