diff --git a/20240823/十四届蓝桥比赛/数独填数.cpp b/20240823/十四届蓝桥比赛/数独填数.cpp index e92b354..7cc258b 100644 --- a/20240823/十四届蓝桥比赛/数独填数.cpp +++ b/20240823/十四届蓝桥比赛/数独填数.cpp @@ -1,32 +1,76 @@ -//NOT DONE #include using namespace std; +int m[10][10]; +bool h_is_used[10][10],l_is_used[10][10],t_is_used[4][4][10]; + #ifdef OI #define DB(code){code} +#define PV(v){cout<<#v<<" : "<<(v)<> find_next(int x,int y); + +int main(){ + for(int i=1;i<=9;i++){ + string str; + getline(cin,str); + for(int j=1;j<=9;j++){ + if(str[j-1]=='.'){ + m[i][j]=-1; + }else{ + m[i][j]=str[j-1]-'0'; + h_is_used[i][m[i][j]]=true; + l_is_used[j][m[i][j]]=true; + t_is_used[i/3+1][j/3+1][m[i][j]]=true; + } + } + } + DB( + for(int i=1;i<=9;i++){ + for(int j=1;j<=9;j++){ + cout<first, find->second); +} + +optional> find_next(int x,int y){ + for (int j=y+1; j<=9; j++) { + if(m[x][j]==-1){ + return make_optional>({x,j}); + } + } + for(int i=x+1;i<=9;i++){ + for(int j=1;j<=9;j++){ + if(m[i][j]==-1){ + return make_optional>({i,j}); + } + } + } + return nullopt; +} -// bool check(int x,int y,int num); -bool check(int x,int y,int num); void dfs(int x,int y){ - if(x==9&&y==9){ + DB(PV(x)PV(y)cout<first, find->second); -// } - -bool check(int x,int y,int num){ - for(int i=1;i<=9;i++){ - if(m[i][y]==num){ - return false; - } + h_is_used[x][i]=false; + l_is_used[y][i]=false; + t_is_used[x/3+1][y/3+1][i]=false; + m[x][y]=-1; } - for(int i=1;i<=9;i++){ - if(m[x][i]==num){ - return false; - } - } - for(int i=x+1,j=y+1;i<=9&&j<=9;i++,j++){ - if(m[i][j]==num){ - return false; - } - } - for(int i=x-1,j=y-1;i>=1&&j>=1;i--,j--){ - if(m[i][j]==num){ - return false; - } - } - return true; -} - -/* -17.5..8.. -.52.1.... -.....759. -.8...94.3 -.197.4..8 -7......15 -4.1...6.. -3...2..59 -...96..3. -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/out.txt b/out.txt new file mode 100644 index 0000000..3a5bd8d Binary files /dev/null and b/out.txt differ diff --git a/xmake.lua b/xmake.lua index 08ec4d7..7f0e66f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,6 +1,7 @@ add_rules("mode.debug","mode.release") if is_mode("debug") then - add_cxxflags("-O2","-DOI") + -- add_cxxflags("-O2","-DOI") + add_cxxflags("-DOI") end set_languages("c++17")