-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path36.cpp
More file actions
99 lines (89 loc) · 2.58 KB
/
36.cpp
File metadata and controls
99 lines (89 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Author : Accagain
// Date : 17/3/27
// Email : chenmaosen0@gmail.com
/***************************************************************************************
*
* Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
*
* The Sudoku board could be partially filled, where empty cells are filled with the character '.'.
*
* A partially filled sudoku which is valid.
*
* Note:
* A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
*
* 做法:
* 直接模拟
* 时间复杂度:
*
*
****************************************************************************************/
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#define INF 0x3fffffff
using namespace std;
class Solution {
public:
bool judge(vector<vector<char>> board, int x1, int y1, int x2, int y2)
{
int hav[10];
memset(hav, 0, sizeof(hav));
for(int i=x1; i<=x2; i++)
for(int j=y1; j<=y2; j++)
{
if(board[i][j] != '.')
{
if(board[i][j] >= '1' && board[i][j] <= '9')
{
if(hav[board[i][j] - '0'])
return false;
hav[board[i][j] - '0'] = 1;
}
else
return false;
}
}
return true;
}
bool isValidSudoku(vector<vector<char>>& board) {
for(int i=0; i<board.size(); i++)
{
bool tmp = judge(board, i, 0, i, 0+board.size()-1);
if(!tmp)
return false;
tmp = judge(board, 0, i, board.size()-1, i);
if(!tmp)
return false;
if(i%3 == 0)
{
for(int j=0; j<board.size(); j++)
{
if(j%3 == 0)
{
int x = i+2;
int y = j+2;
if((x < board.size()) && (y < board.size()))
{
tmp = judge(board, i, j, x, y);
if(!tmp)
return false;
}
}
}
}
}
return true;
}
};
int main() {
Solution *test = new Solution();
int data[] = {};
vector<int> x(data, data + sizeof(data) / sizeof(data[0]));
return 0;
}
//
// Created by cms on 17/3/27.
//