Advertisement
Guest User

Untitled

a guest
Feb 25th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. #define mp make_pair
  7. #define f first
  8. #define s second
  9. typedef pair <int, int> pii;
  10. const int N = 1e5 + 5;
  11.  
  12. pii a[N];
  13. int n, c;
  14. void cntBoys(char p[], int v, int& fir, int& sec)
  15. {
  16.   fir = sec = 0;
  17.   for (int i = 0; i < v; i++)
  18.     if (i%2 == 0 && p[i] == 'B') fir++;
  19.     else if (i%2 && p[i] == 'B') sec++;
  20. }
  21. bool fun(pii x, pii y)
  22. {
  23.   return x.f - x.s >= y.f - y.s;
  24. }
  25. int main()
  26. {
  27.   //freopen("physed.in", "r", stdin);
  28.   //freopen("physed.out", "w", stdout);
  29.   cin >> n;
  30.   int len, ones = 0, all = 0;
  31.   char s[105];
  32.   for (int i = 0; i < n; i++)
  33.   {
  34.     scanf("%s", s);
  35.     len = strlen(s);
  36.     if (len%2)
  37.     {
  38.       cntBoys(s, len, a[c].f, a[c].s);
  39.       c++;
  40.     } else
  41.     {
  42.       int e1, e2;
  43.       cntBoys(s, len, e1, e2);
  44.       ones += e1;
  45.       all += max(e1, e2);
  46.     }
  47.   }
  48.   if (!c)
  49.   {
  50.     cout << ones;
  51.     return 0;
  52.   }
  53.   sort(a, a + c, fun);
  54.   int t = (c + 1) / 2;
  55.   for (int i = 0; i < t; i++)
  56.     all += a[i].f;
  57.   for (int i = t; i < c; i++)
  58.     all += a[i].s;
  59.   cout << all;
  60.   return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement