Advertisement
ca3zsar

Untitled

Feb 25th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n,m;
  6. string s;
  7. string mat[52][52];
  8. map<char,int>f;
  9. string c="23456789TJQKA";
  10. string c2="CDHS";
  11. vector<pair<int,int>>ans;
  12. string jok1="",jok2="";
  13. map<string,int>aux;
  14. int patrat;
  15. int joker;
  16. int x1=-1,Y1=-1,x2=-1,Y2=-1;
  17. int main(){
  18. cin>>n>>m;
  19. for(int i=0;i<n;i++)
  20. {
  21. for(int j=0;j<m;j++)
  22. {
  23. cin>>s;
  24. mat[i][j]=s;
  25. aux[s]++;
  26. }
  27. }
  28. //BRUTE-FORCE
  29. for(int i=0;i<=n-3&&patrat<2;i++)
  30. {
  31. for(int j=0;j<=m-3 &&patrat<2;j++)
  32. {
  33. f.clear();
  34. int to_verify=0;
  35. x1=Y1=x2=Y2=-1;
  36. if(ans.size()==1)
  37. {
  38. if(i<ans[0].first+3 && j<ans[0].second+3)continue;
  39. }else if(ans.size()==2)break;
  40. for(int k1=i;k1<i+3;k1++)
  41. {
  42. for(int k2=j;k2<j+3;k2++)
  43. {
  44. if(mat[k1][k2][0]=='J')
  45. {
  46. if(mat[k1][k2][1]=='1' || mat[k1][k2][1]=='2'){
  47. to_verify++;
  48. if(mat[k1][k2][1]=='1'){x1=k1;Y1=k2;}
  49. else {x2=k1;Y2=k2;}
  50. }else {
  51. f[mat[k1][k2][0]]++;
  52. f[mat[k1][k2][1]]++;
  53. }
  54. }else{
  55. f[mat[k1][k2][0]]++;
  56. f[mat[k1][k2][1]]++;
  57. }
  58. }
  59. }
  60. if(to_verify)
  61. {
  62. int ok=0;
  63. for(int k=0;k<4;k++)
  64. {
  65. if(f[c2[k]]==9-to_verify)
  66. {
  67. ok=0;
  68. for(int k2=0;k2<c.size();k2++)
  69. {
  70. if(f[c[k2]]==0){
  71. if(x1>=0)
  72. {
  73. jok1 = c[k2];
  74. jok1 = jok1+c2[k];
  75. if(aux[jok1]==0)
  76. {
  77. x1=-1;
  78. f[c[k2]]=1;
  79. ok++;
  80. aux[jok1]++;
  81. if(ok==to_verify)break;
  82. }
  83. }else{
  84. if(x2>=0){
  85. jok2 = c[k2];
  86. jok2 = jok2+c2[k];
  87. if(aux[jok2]==0)
  88. {
  89. x2=-1;
  90. f[c[k2]]=1;
  91. ok++;
  92. aux[jok2]++;
  93. if(ok==to_verify)break;
  94. }
  95. }
  96. }
  97. }
  98. }
  99. if(ok!=to_verify){
  100. aux[jok1]=0;
  101. aux[jok2]=0;
  102. ok=0;
  103. }
  104. if(ok==to_verify){
  105. ans.push_back(make_pair(i,j));
  106. patrat++;
  107. break;
  108. }
  109. }
  110. }
  111. if(!ok)
  112. {
  113. ok=1;
  114. for(int k=0;k<c.size();k++)
  115. {
  116. if(f[c[k]]>1)
  117. {
  118. ok=0;
  119. break;
  120. }
  121. }
  122. if(ok)
  123. {
  124. ok=0;
  125. for(int k=0;k<c.size();k++)
  126. {
  127. if(f[c[k]]==0)
  128. {
  129. for(int k2=0;k2<4;k2++)
  130. {
  131. string z;
  132. z = c[k];
  133. z = z+c2[k2];
  134. if(x1>=0)
  135. {
  136. if(aux[z]==0 && f[c[k]]==0)
  137. {
  138. jok1=z;
  139. x1=-1;
  140. f[c2[k]]=1;
  141. ok++;
  142. aux[jok1]++;
  143. }
  144.  
  145. }else{
  146. if(x2>=0){
  147. jok2 = z;
  148. if(aux[jok2]==0 && f[c[k]]==0)
  149. {
  150. x2=-1;
  151. f[c2[k]]=1;
  152. ok++;
  153. aux[jok2]++;
  154. }
  155. }
  156. }
  157. }
  158. }
  159.  
  160. }
  161. if(ok==to_verify)
  162. {
  163. ans.push_back(make_pair(i,j));
  164. patrat++;
  165. j+=2;
  166. }else{
  167. aux[jok1]=0;
  168. aux[jok2]=0;
  169. }
  170. }
  171. }else{
  172. ans.push_back(make_pair(i,j));
  173. patrat++;
  174. j+=2;
  175. }
  176. }else{
  177. int ok=0;
  178. for(int k=0;k<4;k++)
  179. {
  180. if(f[c2[k]]==9)
  181. {
  182. patrat++;
  183. ok=1;
  184. ans.push_back(make_pair(i,j));
  185. break;
  186. }
  187. }
  188. if(!ok)
  189. {
  190. for(int k=0;k<c.size();k++)
  191. {
  192. if(f[c[k]]>1)
  193. {
  194. ok=1;
  195. break;
  196. }
  197. }
  198. if(!ok)
  199. {
  200. patrat++;
  201. ok=1;
  202. ans.push_back(make_pair(i,j));
  203. }
  204. }
  205.  
  206. }
  207. }
  208. }
  209. if(patrat>=2)
  210. {
  211. cout<<"Solution exists.\n";
  212.  
  213. if(jok1=="" && jok2==""){
  214. cout<<"There are no jokers.\n";
  215. cout<<"Put the first square to ("<<ans[0].first+1<<", "<<ans[0].second+1<<").\n";
  216. cout<<"Put the second square to ("<<ans[1].first+1<<", "<<ans[1].second+1<<").\n";
  217. }else{
  218. if(jok1!="" && jok2!="")cout<<"Replace J1 with "<<jok1<<" and J2 with "<<jok2<<".\n";
  219. else{if(jok1!="")cout<<"Replace J1 with "<<jok1<<".\n";
  220. if(jok2!="")cout<<"Replace J2 with "<<jok2<<".\n";}
  221. cout<<"Put the first square to ("<<ans[0].first+1<<", "<<ans[0].second+1<<").\n";
  222. cout<<"Put the second square to ("<<ans[1].first+1<<", "<<ans[1].second+1<<").\n";
  223. }
  224. }else{
  225. cout<<"No solution.";
  226. }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement