Advertisement
Saleh127

UVA 12988

Feb 22nd, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. bool visit[10][10];
  6. char a[10][10];
  7. bool check(ll r,ll c,char x)
  8. {
  9. ll i,j;
  10. for(i=0;i<4;i++)
  11. {
  12. if(a[i][c]==x) return 0;
  13. }
  14. for(i=0;i<4;i++)
  15. {
  16. if(a[r][i]==x) return 0;
  17. }
  18. if((r==0 || r==1) && (c==0 || c==1) && (a[0][0]==x || a[0][1]==x || a[1][0]==x || a[1][1]==x))
  19. {
  20. return 0;
  21. }
  22. else if((r==0 || r==1) && (c==2 || c==3) && (a[0][2]==x || a[0][3]==x || a[1][2]==x || a[1][3]==x))
  23. {
  24. return 0;
  25. }
  26. else if((r==2 || r==3) && (c==0 || c==1) && (a[2][1]==x || a[2][0]==x || a[3][0]==x || a[3][1]==x))
  27. {
  28. return 0;
  29. }
  30. else if((r==2 || r==3) && (c==2 || c==3) && (a[2][2]==x || a[2][3]==x || a[3][2]==x || a[3][3]==x))
  31. {
  32. return 0;
  33. }
  34. else return 1;
  35. }
  36.  
  37. void dfs(ll r, ll c)
  38. {
  39. if(r==3 && c==(r+1))
  40. {
  41. for(ll i=0;i<4;i++)
  42. {
  43. for(ll j=0;j<4;j++)
  44. {
  45. cout<<a[i][j];
  46. }
  47. cout<<endl;
  48. }
  49. return ;
  50. }
  51. if(r>=4) return;
  52.  
  53. if(c>=4)
  54. {
  55. r++;
  56. c=0;
  57. }
  58. if(a[r][c]!='*')
  59. {
  60. dfs(r,c+1);
  61. }
  62. for(char z='1';z<='4';z++)
  63. {
  64. if(check(r,c,z)==1 && visit[r][c]==0 && a[r][c]=='*')
  65. {
  66. visit[r][c]=1;
  67. a[r][c]=z;
  68. dfs(r,c+1);
  69. visit[r][c]=0;
  70. a[r][c]='*';
  71. }
  72. }
  73.  
  74. }
  75.  
  76. int main()
  77. {
  78. ios_base::sync_with_stdio(0);
  79. cin.tie(0);cout.tie(0);
  80.  
  81. test
  82. {
  83. memset(visit,0,sizeof(visit));
  84. a[10][10]='\0';
  85. string dd;
  86. getline(cin,dd);
  87. for(ll i=0;i<4;i++)
  88. {
  89. for(ll j=0;j<4;j++)
  90. {
  91. cin>>a[i][j];
  92. }
  93. }
  94. cout<<"Case #"<<cs<<":"<<endl;
  95. dfs(0,0);
  96. }
  97.  
  98. return 0;
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement