Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <string>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <ctime>
  11. using namespace std;
  12.  
  13. const int N = 1e5 + 5;
  14. int per[N], perwin[8], sz = 0;
  15. char s[N][4];
  16. pair<int, int> arr[N];
  17. int ans = 5;
  18.  
  19. inline int getnum(char c) {
  20.     if (c == 'A') return 1;
  21.     if (c == 'B') return 2;
  22.     return 4;
  23. }
  24.  
  25. inline int getnum(int id) {
  26.     int ans = 0;
  27.     for (int i = 0; s[id][i]; ++i)
  28.         ans |= getnum(s[id][i]);
  29.     return ans;
  30. }
  31.  
  32. bool comp(const pair<int, int>& a, const pair<int, int>& b) {
  33.     return per[a.first] < per[b.first];
  34. }
  35.  
  36. int main() {
  37.     for (int i = 0; i < 8; ++i)
  38.         per[i] = i;
  39.     int n;
  40.     cin >> n;
  41.     gets(s[0]);
  42.     for (int i = 0; i < n; ++i)
  43.         gets(s[i]);
  44.     for (int i = 0; i < n; ++i) {
  45.         arr[i] = make_pair(getnum(i), i);
  46.         per[i] = arr[i].first;
  47.     }
  48.     sort(per, per + n);
  49.     sz = unique(per, per + n) - per;
  50.     do {
  51.         int q = 0;
  52.         for (int i = 0; i < sz; ++i) {
  53.             for (int j = 0; j < 3; ++j) {
  54.                 if ((per[i] & (1 << j)) && (!i || !(per[i-1] & (1 << j))))
  55.                     ++q;
  56.             }
  57.         }
  58.         if (q < ans) {
  59.             ans = q;
  60.             for (int i = 0; i < sz; ++i)
  61.                 perwin[i] = per[i];
  62.         }
  63.     } while (next_permutation(per, per + sz));
  64.  
  65.     cout << ans << endl;
  66.     for (int i = 0; i < sz; ++i)
  67.         per[i] = perwin[i];
  68.  
  69.     for (int i = 0; i < sz; ++i)
  70.         cout << per[i] << " ";
  71.     cout << endl;
  72.  
  73.     // vot do suda vse normalno
  74.  
  75.     sort(arr, arr + n, comp);
  76.     for (int i = 0; i < n; ++i)
  77.         printf("%d ", arr[i].second + 1);
  78.     cout << endl;
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement