【杂题】 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; }
相关文章推荐
- codeforces 417B - Crash
- Codeforces 274A k-Multiple Free Set
- Codeforces 249D Donkey and Stars (线段树+扫描线)
- 【codeforces】Codeforces Round #366 (Div. 2)
- codeforces 805A - Fake NP
- codeforces 868D 分治哈希
- Codeforces 417C Football(构造)
- codeforces 482 B Interesting Array <STL map 的运用>
- codeforces 6E. Exposition(RMQ + 二分)
- CodeForces 550C Divisibility by Eight (规律,暴力)
- codeforces 797B Odd sum
- 【CodeForces】 652B
- CodeForces 248B Chilly Willy
- Codeforces 156D Clues (图论, 并查集, 卡特兰数)
- 【codeforces】-#621-AWet Shark and Odd and Even(n个数最大偶数和)
- Codeforces 278C Learning Languages【并查集】水题
- CodeForces - 808F Card Game (随机化大法)
- Codeforces 851D Arpa and a list of numbers
- CodeForces 275C k-Multiple Free Set
- CodeForces 496C 字符串阵处理