SRM 386(1-250pt)

DIV1 250pt

题意:题意很难翻译。。。。其实就是一个暴力。。。在看到有一个限制条件的范围为1-10的时候就该想到是暴力,我却半天没想到。。。。

tag:brute-force

  1 // BEGIN CUT HERE
  2 /*
  3  * Author:  plum rain
  4  * score :
  5  */
  6 /*
  7 
  8  */
  9 // END CUT HERE
 10 #line 11 "CandidateKeys.cpp"
 11 #include <sstream>
 12 #include <stdexcept>
 13 #include <functional>
 14 #include <iomanip>
 15 #include <numeric>
 16 #include <fstream>
 17 #include <cctype>
 18 #include <iostream>
 19 #include <cstdio>
 20 #include <vector>
 21 #include <cstring>
 22 #include <cmath>
 23 #include <algorithm>
 24 #include <cstdlib>
 25 #include <set>
 26 #include <queue>
 27 #include <bitset>
 28 #include <list>
 29 #include <string>
 30 #include <utility>
 31 #include <map>
 32 #include <ctime>
 33 #include <stack>
 34 
 35 using namespace std;
 36 
 37 #define clr0(x) memset(x, 0, sizeof(x))
 38 #define clr1(x) memset(x, -1, sizeof(x))
 39 #define pb push_back
 40 #define sz(v) ((int)(v).size())
 41 #define all(t) t.begin(),t.end()
 42 #define zero(x) (((x)>0?(x):-(x))<eps)
 43 #define out(x) cout<<#x<<":"<<(x)<<endl
 44 #define tst(a) cout<<a<<" "
 45 #define tst1(a) cout<<#a<<endl
 46 #define CINBEQUICKER std::ios::sync_with_stdio(false)
 47 
 48 typedef vector<int> vi;
 49 typedef vector<string> vs;
 50 typedef vector<double> vd;
 51 typedef pair<int, int> pii;
 52 typedef long long int64;
 53 
 54 const double eps = 1e-8;
 55 const double PI = atan(1.0)*4;
 56 const int inf = 2139062143 / 2;
 57 
 58 class CandidateKeys
 59 {
 60     public:
 61         bool v[10000];
 62         int n, m, u[100][100];
 63         vector<pii > pat[20];
 64 
 65         bool gao(int sta)
 66         {
 67             clr0 (u);
 68             for (int i = 0; i < m; ++ i) if (sta & (1<<i)){
 69                 for (int j = 0; j < sz(pat[i]); ++ j){
 70                     int t1 = pat[i][j].first, t2 = pat[i][j].second;
 71                     u[t1][t2] =  u[t2][t1] = 1;
 72                 }
 73             }
 74 
 75             for (int i = 0; i < n; ++ i)
 76                 for (int j = i+1; j < n; ++ j)
 77                     if (!u[i][j]) return 0;
 78             return 1;
 79         }
 80 
 81         vector <int> getKeys(vector <string> tab){
 82             m = sz(tab[0]); n = sz(tab);
 83             for (int i = 0; i < m; ++ i){
 84                 pat[i].clear();
 85                 for (int j = 0; j < n; ++ j)
 86                     for (int k = j+1; k < n; ++ k)
 87                         if (tab[k][i] != tab[j][i])
 88                             pat[i].pb (make_pair(k, j));
 89             }
 90             
 91             clr0 (v);
 92             vi ans; ans.pb (100); ans.pb (-1);
 93             for (int i = 0; i < (1<<m); ++ i){
 94                 for (int j = 0; j < m; ++ j)
 95                     if (v[i^(1<<j)]) v[i] = 1;
 96                 if (v[i]) continue;
 97                 
 98                 if (gao(i)){
 99                     ans[0] = min(ans[0], __builtin_popcount(i));
100                     ans[1] = max(ans[1], __builtin_popcount(i));
101                     v[i] = 1;
102                 }
103             }
104             if (ans[0] == 100) ans.clear();
105             return ans;
106         }
107         
108 // BEGIN CUT HERE
109     public:
110     void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
111     //void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_2();}
112     private:
113     template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
114     void verify_case(int Case, const vector <int> &Expected, const vector <int> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } }
115     void test_case_0() { string Arr0[] = {
116 "ABC",
117 "ABC",
118 "ABC"
119 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = { }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(0, Arg1, getKeys(Arg0)); }
120     void test_case_1() { string Arr0[] = {
121 "ABC",
122 "ABD",
123 "ABE"
124 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1, 1 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(1, Arg1, getKeys(Arg0)); }
125     void test_case_2() { string Arr0[] = {
126 "ABC",
127 "ACD",
128 "BBE"
129 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1, 2 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(2, Arg1, getKeys(Arg0)); }
130     void test_case_3() { string Arr0[] = {"A","B"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1, 1 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(3, Arg1, getKeys(Arg0)); }
131     void test_case_4() { string Arr0[] = {
132 "AABB",
133 "BABA",
134 "CAAB",
135 "DAAA",
136 "EBBB",
137 "FBBA",
138 "GBAB",
139 "HBAA"
140 }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1, 3 }; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(4, Arg1, getKeys(Arg0)); }
141 
142 // END CUT HERE
143 
144 };
145 
146 // BEGIN CUT HERE
147 int main()
148 {
149 //    freopen( "a.out" , "w" , stdout );    
150     CandidateKeys ___test;
151     ___test.run_test(-1);
152        return 0;
153 }
154 // END CUT HERE
View Code

 

posted @ 2014-01-04 00:53  Plumrain  阅读(171)  评论(0编辑  收藏  举报