标签:target oar log lan style 提示 net sudo get
bool isValidSudoku(vector<vector<char> > &board) { const int M = 9;//9 * 9 const int hash_len = 60;//'0' = 48 + 10 const char dot = '.'; //check rows for(int i = 0; i < M; ++i) { bool rows[hash_len] = {false}; bool cols[hash_len] = {false}; for(int j = 0; j < M; ++j){ if(board[i][j] != dot) { if(rows[board[i][j]]) return false; else rows[board[i][j]] = true; } } } //check cols for(int i = 0; i < M; ++i) { bool rows[hash_len] = {false}; for(int j = 0; j < M; ++j){ if(board[j][i] != dot) { if(rows[board[j][i]]) return false; else rows[board[j][i]] = true; } } } //check inner boxes. 9 * (3 * 3) const int N = 3; for(int ibox = 0; ibox < M; ++ibox) { bool box[hash_len] = {false}; for (int irow = 0; irow < N; ++irow) { for (int icol = 0; icol < N; ++icol) { if(board[ibox/N*N + irow][ibox%N*N + icol] != dot && box[board[ibox/N*N + irow][ibox%N*N + icol]]) return false; if(board[ibox/N*N + irow][ibox%N*N + icol] != dot) box[board[ibox/N*N + irow][ibox%N*N + icol]] = true; } } } return true; }
标签:target oar log lan style 提示 net sudo get
原文地址:http://www.cnblogs.com/mthoutai/p/6992440.html