Advertisement
royalsflush

Referência para TopCoder Teaching (Luiza)

Apr 6th, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <math.h>
  2. #include <time.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. #include <iostream>
  7. #include <string>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <queue>
  11. using namespace std;
  12.  
  13. #define TRACE(x) x
  14. #define PRINT(x) TRACE(printf(x))
  15. #define WATCH(x) TRACE(cout << #x << " = " << x << endl;)
  16.  
  17. #define rep(i,n) for (int i=0; i<n; i++)
  18.  
  19. const int inf =0x3f3f3f3f;
  20. const double eps = 1e-9;
  21.  
  22. char s[30] = "qweryuopsdfghjklzxvbm";
  23. int w[20];
  24.  
  25. void printBm(int x) {
  26.     for (int i=0; i<21; i++)
  27.         if (x&(1<<i)) printf("1");
  28.         else printf("0");
  29.     printf("\n");
  30. }
  31.  
  32. class Teaching {
  33. public:
  34.    int count( vector <string> words, int K ) {
  35.     for (int i=0; i<words.size(); i++) {
  36.         int bm=0;
  37.  
  38.         for (int j=0; j<words[i].size(); j++) {
  39.             for (int k=0; s[k]!='\0'; k++)
  40.                 if (words[i][j]==s[k])
  41.                     bm|=(1<<k);
  42.         }
  43.        
  44.         w[i]=bm;
  45.     }
  46.  
  47.     int maxW=0;
  48.     for (int i=0; i<(1<<21); i++)
  49.         if (__builtin_popcount(i)==K-5) {
  50.             int cnt=0;
  51.  
  52.             for (int j=0; j<words.size(); j++)
  53.                 if ((w[j]&i)==w[j]) ++cnt;
  54.             maxW=max(maxW,cnt);
  55.         }
  56.  
  57.     return maxW;
  58.    }
  59. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement