|
| 1 | +#include <iostream> |
| 2 | +#include <sstream> |
| 3 | +#include <vector> |
| 4 | +#include <algorithm> |
| 5 | +#include <set> |
| 6 | +#include <map> |
| 7 | +#include <queue> |
| 8 | +#include <cstring> |
| 9 | +#include <climits> |
| 10 | +#include <cstdio> |
| 11 | +using namespace std; |
| 12 | +typedef pair<int, int> pi; |
| 13 | +typedef pair<char, char> pc; |
| 14 | +typedef vector<int> vi; |
| 15 | +typedef vector<vi> vvi; |
| 16 | +typedef vector<string> vs; |
| 17 | +typedef vector<vs> vvs; |
| 18 | + |
| 19 | +class BioScore{ |
| 20 | + public: |
| 21 | + |
| 22 | + double maxAvg(vector <string> knownSet) { |
| 23 | + |
| 24 | + vi ex(10); |
| 25 | + int n = knownSet.size(); |
| 26 | + map<pc, int> P, D; |
| 27 | + P[make_pair('A', 'C')] = P[make_pair('C', 'A')] = 0; |
| 28 | + P[make_pair('A', 'T')] = P[make_pair('T', 'A')] = 1; |
| 29 | + P[make_pair('A', 'G')] = P[make_pair('G', 'A')] = 2; |
| 30 | + P[make_pair('T', 'C')] = P[make_pair('C', 'T')] = 3; |
| 31 | + P[make_pair('G', 'C')] = P[make_pair('C', 'G')] = 4; |
| 32 | + P[make_pair('G', 'T')] = P[make_pair('T', 'G')] = 5; |
| 33 | + |
| 34 | + P[make_pair('A', 'A')] = 6; |
| 35 | + P[make_pair('C', 'C')] = 7; |
| 36 | + P[make_pair('T', 'T')] = 8; |
| 37 | + P[make_pair('G', 'G')] = 9; |
| 38 | + |
| 39 | + for(int i = 0; i < n; i++) |
| 40 | + for(int j = i+1; j < n; j++){ |
| 41 | + string s = knownSet[i], t = knownSet[j]; |
| 42 | + for(int k = 0; k < s.size(); k++) |
| 43 | + ex[P[make_pair(s[k], t[k])]]++; |
| 44 | + } |
| 45 | + |
| 46 | + sort(ex.begin(), ex.begin()+6); |
| 47 | + |
| 48 | + int ret = -1000000000; |
| 49 | + for(int i = 1; i <= 10; i++) |
| 50 | + for(int j = 1; j <= 10; j++) |
| 51 | + for(int k = 1; k <= 10; k++) |
| 52 | + for(int l = 1; l <= 10; l++) |
| 53 | + if((i+j+k+l)%2 == 0){ |
| 54 | + int t = 10-(i+j+k+l)/2; |
| 55 | + int v = (-10*ex[0]-10*ex[1]-10*ex[2]+t*ex[3]+10*ex[4]+10*ex[5]) + i*ex[6]+j*ex[7]+k*ex[8]+l*ex[9]; |
| 56 | + ret = max(ret, v); |
| 57 | + } |
| 58 | + |
| 59 | + return (2*(double)ret)/(n*(n-1)); |
| 60 | + } |
| 61 | + |
| 62 | +// BEGIN CUT HERE |
| 63 | + public: |
| 64 | + 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(); } |
| 65 | + private: |
| 66 | + 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(); } |
| 67 | + void verify_case(int Case, const double &Expected, const double &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } |
| 68 | + void test_case_0() { string Arr0[] = {"AAA","AAA","AAC"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); double Arg1 = 30.0; verify_case(0, Arg1, maxAvg(Arg0)); } |
| 69 | + void test_case_1() { string Arr0[] = {"ACTGACTGACTG","GACTTGACCTGA"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); double Arg1 = -4.0; verify_case(1, Arg1, maxAvg(Arg0)); } |
| 70 | + void test_case_2() { string Arr0[] = {"ACTAGAGAC","AAAAAAAAA","TAGTCATAC","GCAGCATTC"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); double Arg1 = 50.5; verify_case(2, Arg1, maxAvg(Arg0)); } |
| 71 | + |
| 72 | +// END CUT HERE |
| 73 | + |
| 74 | +}; |
| 75 | + |
| 76 | +// BEGIN CUT HERE |
| 77 | +int main(){ |
| 78 | + |
| 79 | + BioScore ___test; |
| 80 | + ___test.run_test(-1); |
| 81 | +} |
| 82 | +// END CUT HERE |
0 commit comments