标签:cout 电路 ace 绿色 oar proc cep 颜色 got
3 RGGBBGGRBRRGGBG RBGRBGRBGRBGRBG RRRRGBBBRGGRBBB GGRGBGGBRRGGGBG GBGGRRRRRBGGRRR BBBBBBBBBBBBBBB BBBBBBBBBBBBBBB RRRRRRRRRRRRRRR RRRRRRGGGGRRRRR GGGGGGGGGGGGGGG RRRRRRRRRRRRRRR RRRRRRRRRRRRRRR GGGGGGGGGGGGGGG GGGGGGGGGGGGGGG BBBBBBBBBBBBBBB BBBBBBBBBBBBBBB RRRRRRRRRRRRRRR RRRRRRRRRRRRRRR GGGGGGGGGGGGGGG GGGGGGGGGGGGGGG RBGRBGRBGRBGRBG BGRBGRBGRBGRBGR GRBGRBGRBGRBGRB RBGRBGRBGRBGRBG BGRBGRBGRBGRBGR GRBGRBGRBGRBGRB RBGRBGRBGRBGRBG BGRBGRBGRBGRBGR GRBGRBGRBGRBGRB RBGRBGRBGRBGRBG样例输出
Game 1: Move 1 at (4,1): removed 32 balls of color B, got 900 points. Move 2 at (2,1): removed 39 balls of color R, got 1369 points. Move 3 at (1,1): removed 37 balls of color G, got 1225 points. Move 4 at (3,4): removed 11 balls of color B, got 81 points. Move 5 at (1,1): removed 8 balls of color R, got 36 points. Move 6 at (2,1): removed 6 balls of color G, got 16 points. Move 7 at (1,6): removed 6 balls of color B, got 16 points. Move 8 at (1,2): removed 5 balls of color R, got 9 points. Move 9 at (1,2): removed 5 balls of color G, got 9 points. Final score: 3661, with 1 balls remaining. Game 2: Move 1 at (1,1): removed 30 balls of color G, got 784 points. Move 2 at (1,1): removed 30 balls of color R, got 784 points. Move 3 at (1,1): removed 30 balls of color B, got 784 points. Move 4 at (1,1): removed 30 balls of color G, got 784 points. Move 5 at (1,1): removed 30 balls of color R, got 784 points. Final score: 4920, with 0 balls remaining. Game 3: Final score: 0, with 150 balls remaining.
////////////////////////////////////////////////////////////////////////// // POJ1027 The Same Game // Memory: 288K Time: 500MS // Language: C++ Result: Accepted ////////////////////////////////////////////////////////////////////////// #include <iostream> #include <stdio.h> using namespace std; int gameCnt; char board[11][16]; int record[11][16]; int rows[15]; int maxRow = 0; int maxCol = 0; char color = ‘ ‘; int maxCluster = 0; int score; int bfs(int row, int col) { if (board[row][col] == 0) { return 0; } color = board[row][col]; int cluster = 1; record[row][col] = 1; if (board[row + 1][col] != 0 && record[row + 1][col] == 0 && board[row + 1][col] == color) { cluster += bfs(row + 1, col); } if (board[row - 1][col] != 0 && record[row - 1][col] == 0 && board[row - 1][col] == color) { cluster += bfs(row - 1, col); } if (board[row][col + 1] != 0 && record[row][col + 1] == 0 && board[row][col + 1] == color) { cluster += bfs(row, col + 1); } if (board[row][col - 1] != 0 && record[row][col - 1] == 0 && board[row][col - 1] == color) { cluster += bfs(row, col - 1); } return cluster; } void clear(int row, int col) { board[row][col] = 0; if (board[row + 1][col] != 0 && board[row + 1][col] == color) { clear(row + 1, col); } if (board[row - 1][col] != 0 && board[row - 1][col] == color) { clear(row - 1, col); } if (board[row][col + 1] != 0 && board[row][col + 1] == color) { clear(row, col + 1); } if (board[row][col - 1] != 0 && board[row][col - 1] == color) { clear(row, col - 1); } } void process(int row, int col) { clear(row, col); int r = 0, c = 0; for (c = 0; c < 15; ++c) { int i, j; for (i = 0; i < 10 && board[i][c] != 0; ++i) { continue; } for (j = i; j < 10 && board[j][c] == 0; ++j) { continue; } while (i < 10) { if (j > 10) { board[i++][c] = 0; continue; } if (board[j][c] == 0) { ++j; continue; } board[i++][c] = board[j++][c]; } } int i = 0, j = 0; for (i = 0; i < 15 && board[0][i] != 0; ++i) { continue; } for (j = i; j < 15 && board[0][j] == 0; ++j) { continue; } while (i < 15) { if (j > 15) { for (int k = 0; k <= 10; ++k) { board[k][i] = 0; } ++i; continue; } if (board[0][j] == 0) { ++j; continue; } for (int k = 0; k <= 10; ++k) { board[k][i] = board[k][j]; } ++i; ++j; } } int main() { cin >> gameCnt; for (int gameId = 1; gameId <= gameCnt; ++gameId) { int row, col; memset(record, 0, sizeof(record)); color = ‘ ‘; maxCluster = 0; for (row = 9; row >= 0; --row) { for (col = 0; col < 15; ++col) { cin >> board[row][col]; } } int move = 1; int score = 0; int remain = 150; cout << "Game " << gameId << ":" << endl << endl; while (true) { maxCluster = 0; memset(record, 0, sizeof(record)); for (row = 0, col = 0; board[row][col] != 0; ++col) { for (row = 0; board[row][col] != 0; ++ row) { if (record[row][col] != 0) continue; int cluster = bfs(row, col); if (cluster > maxCluster) { maxRow = row; maxCol = col; maxCluster = cluster; } } row = 0; } color = board[maxRow][maxCol]; if (maxCluster < 2) { break; } int point = (maxCluster - 2) * (maxCluster - 2); remain -= maxCluster; cout << "Move "<< move << " at (" << maxRow + 1 << ","<< maxCol + 1 << "): removed " << maxCluster <<" balls of color " << color << ", got " << point << " points." << endl; ++move; score += point; process(maxRow, maxCol); } if (remain == 0) { score += 1000; } cout << "Final score: " << score << ", with " << remain << " balls remaining." << endl << endl; } system("pause"); return 0; }
来源:https://www.cnblogs.com/dengeven/p/3228977.html
标签:cout 电路 ace 绿色 oar proc cep 颜色 got
原文地址:https://www.cnblogs.com/sweet-ginger-candy/p/11518210.html