AOJ 1075 - High and Low Cube
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1075
解法
単なる実装ゲー.
aoj/1075.cc1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 6 int parse(const vector<string>& subgrid) 7 { 8 unsigned s = 0; 9 s |= ((subgrid[1][3] == '-') << 6); 10 s |= ((subgrid[2][2] == '|') << 5); 11 s |= ((subgrid[2][4] == '|') << 4); 12 s |= ((subgrid[3][3] == '-') << 3); 13 s |= ((subgrid[4][2] == '|') << 2); 14 s |= ((subgrid[4][4] == '|') << 1); 15 s |= ((subgrid[5][3] == '-') << 0); 16 switch (s) { 17 case 19: return 1; 18 case 93: return 2; 19 case 91: return 3; 20 case 58: return 4; 21 case 107: return 5; 22 case 111: return 6; 23 case 82: return 7; 24 case 127: return 8; 25 case 123: return 9; 26 default: throw "unrecognized char"; 27 } 28 } 29 30 void lr(vector<string>& subgrid) 31 { 32 for (vector<string>::iterator it = subgrid.begin(); it != subgrid.end(); ++it) { 33 reverse(it->begin(), it->end()); 34 } 35 } 36 37 void ud(vector<string>& subgrid) 38 { 39 reverse(subgrid.begin(), subgrid.end()); 40 } 41 42 void rot(vector<string>& subgrid) 43 { 44 const vector<string> src(subgrid); 45 for (int i = 0; i < 7; i++) { 46 for (int j = 0; j < 7; j++) { 47 if (src[i][j] == '|') { 48 subgrid[6-j][i] = '-'; 49 } else if (src[i][j] == '-') { 50 subgrid[6-j][i] = '|'; 51 } else { 52 subgrid[6-j][i] = src[i][j]; 53 } 54 } 55 } 56 } 57 58 int main() 59 { 60 string line; 61 while (cin >> line && line != "0") { 62 vector<string> lines(1, line); 63 for (int i = 1; i < 21; i++) { 64 cin >> line; 65 lines.push_back(line); 66 } 67 int d[2][6]; 68 for (int k = 0; k < 2; k++) { 69 static const int tbl[][2] = {{0,7},{7,0},{7,7},{7,14},{7,21},{14,7}}; 70 for (int i = 0; i < 6; i++) { 71 vector<string> grid; 72 for (int j = 0; j < 7; j++) { 73 grid.push_back(lines[tbl[i][0]+j].substr(tbl[i][1]+29*k, 7)); 74 } 75 switch (i) { 76 case 0: 77 case 2: 78 case 4: 79 lr(grid); 80 break; 81 case 1: 82 rot(grid); 83 rot(grid); 84 rot(grid); 85 lr(grid); 86 break; 87 case 3: 88 rot(grid); 89 lr(grid); 90 break; 91 case 5: 92 lr(grid); 93 ud(grid); 94 break; 95 } 96 d[k][i] = parse(grid); 97 } 98 } 99 int w[2] = {0, 0}; 100 for (int i = 0; i < 6; i++) { 101 for (int j = 0; j < 6; j++) { 102 if (d[0][i] > d[1][j]) { 103 ++w[0]; 104 } else if (d[0][i] < d[1][j]) { 105 ++w[1]; 106 } 107 } 108 } 109 cout << (w[0] < w[1] ? "LOW" : "HIGH") << endl; 110 } 111 return 0; 112 }