Advertisement
PedalaVasile

cusaturi - proasta

Dec 6th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stack>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. ifstream fin("cusaturi.in");
  9. ofstream fout("cusaturi.out");
  10.  
  11. struct motive
  12. {
  13. int st, dr, jos, sus;
  14. int cate = 0;
  15. int cl, cc;
  16. bool vizitat = false;
  17. };
  18.  
  19. motive mot[101];
  20.  
  21. stack < pair < int, int > > s;
  22.  
  23. int di[] = {-1, -1, 0, 1, 1, 1, 0, -1};
  24. int dj[] = {0, 1, 1, 1, 0, -1, -1, -1};
  25.  
  26. int mat[101][101];
  27.  
  28. int c, n, m;
  29.  
  30. void FILL(int i, int j, int nr)
  31. {
  32. mot[nr].sus = i;
  33. mot[nr].jos = i;
  34. mot[nr].st = j;
  35. mot[nr].dr = j;
  36. s.push(make_pair(i, j));
  37.  
  38. while(!s.empty())
  39. {
  40. i = s.top().first;
  41. j = s.top().second;
  42.  
  43. mat[i][j] = nr;
  44.  
  45. if(mot[nr].sus > i)
  46. mot[nr].sus = i;
  47.  
  48. if(mot[nr].jos < i)
  49. mot[nr].jos = i;
  50.  
  51. if(mot[nr].st > j)
  52. mot[nr].st = j;
  53.  
  54. if(mot[nr].dr < j)
  55. mot[nr].dr = j;
  56.  
  57. mot[nr].cate++;
  58.  
  59.  
  60.  
  61. s.pop();
  62.  
  63. for(int k = 0; k < 8; k++)
  64. {
  65. int nexti = i + di[k];
  66. int nextj = j + dj[k];
  67.  
  68. if(mat[nexti][nextj] == -1)
  69. {
  70. mat[nexti][nextj] = nr;
  71. s.push(make_pair(nexti, nextj));
  72. }
  73. }
  74. }
  75.  
  76. mot[nr].cl = mot[nr].jos - mot[nr].sus + 1;
  77. mot[nr].cc = mot[nr].dr - mot[nr].st + 1;
  78. }
  79.  
  80. bool motEchi(motive &a, motive &b)
  81. {
  82. if(b.vizitat == true)
  83. return false;
  84.  
  85. bool oke = true;
  86.  
  87. if(a.cate != b.cate)
  88. return false;
  89.  
  90. if(a.cl != b.cl || a.cc != b.cc)
  91. return false;
  92.  
  93. //fout << a.sus + 1 << ' ' << a.st + 1<< ' ' << a.jos + 1<< ' ' << a.dr + 1<< '\n';
  94. //fout << b.sus + 1 << ' ' << b.st + 1 << ' ' << b.jos + 1 << ' ' << b.dr + 1 << "\n\n";
  95.  
  96. for(int i = 0; i < a.cl; i++)
  97. {
  98. for(int j = 0; j < a.cc; j++)
  99. {
  100. if(mat[a.sus + i][a.st + j] != mat[b.sus + i][b.st + j])
  101. {
  102. oke = false;
  103. break;
  104. }
  105. }
  106. if(!oke)
  107. break;
  108. }
  109.  
  110. if(!oke)
  111. {
  112. oke = true;
  113.  
  114. for(int i = 0; i < a.cl; i++)
  115. {
  116. for(int j = 0; j < a.cc; j++)
  117. {
  118. if(mat[a.sus + i][a.st + j] != mat[b.sus + i][b.dr - j])
  119. {
  120. oke = false;
  121. break;
  122. }
  123. }
  124.  
  125. if(!oke)
  126. break;
  127. }
  128. }
  129. else
  130. {
  131. b.vizitat = true;
  132. return true;
  133. }
  134.  
  135.  
  136.  
  137. if(!oke)
  138. {
  139. oke = true;
  140.  
  141. for(int i = a.cl - 1; i > -1; i--)
  142. {
  143. for(int j = 0; j < a.cc; j++)
  144. {
  145. if(mat[a.sus + i][a.st + j] != mat[b.jos - i][b.st + j])
  146. {
  147. oke = false;
  148. break;
  149. }
  150. }
  151.  
  152. if(!oke)
  153. break;
  154. }
  155. }
  156. else
  157. {
  158. b.vizitat = true;
  159. return true;
  160. }
  161.  
  162.  
  163.  
  164.  
  165. if(!oke)
  166. {
  167. oke = true;
  168.  
  169. for(int i = a.cl - 1; i > -1; i--)
  170. {
  171. for(int j = 0; j < a.cc; j++)
  172. {
  173. if(mat[a.sus + i][a.st + j] != mat[b.jos - i][b.dr + j])
  174. {
  175. oke = false;
  176. break;
  177. }
  178. }
  179.  
  180. if(!oke)
  181. break;
  182. }
  183. }
  184. else
  185. {
  186. b.vizitat = true;
  187. return true;
  188. }
  189.  
  190.  
  191.  
  192.  
  193. if(!oke)
  194. return false;
  195.  
  196.  
  197. b.vizitat = true;
  198. return true;
  199. }
  200.  
  201. int main()
  202. {
  203. fin >> c >> n >> m;
  204.  
  205. char car;
  206.  
  207. for(int i = 0; i < n; i++)
  208. {
  209. for(int j = 0; j < m; j++)
  210. {
  211. fin >> car;
  212. if(car == 'X')
  213. mat[i][j] = -1;
  214. }
  215. }
  216.  
  217. int cate = 0;
  218.  
  219. for(int i = 0; i < n; i++)
  220. {
  221. for(int j = 0; j < m; j++)
  222. {
  223. if(mat[i][j] == -1)
  224. {
  225. cate++;
  226. FILL(i, j, cate);
  227. }
  228. }
  229. }
  230.  
  231. fout << cate << '\n';
  232.  
  233. for(int i = 1; i <= cate; i++)
  234. {
  235. int asem = 1;
  236.  
  237. if(mot[i].vizitat == false)
  238. {
  239. //fout << i << ' ' << mot[i].sus << ' ' << mot[i].st << ' ' << mot[i].jos << ' ' << mot[i].dr << '\n';
  240. for(int j = i + 1; j < cate; j++)
  241. {
  242. if(mot[j].vizitat == false && !motEchi(mot[i], mot[j]))
  243. {
  244. mot[j].vizitat = true;
  245. //fout << mot[j].sus << ' ' << mot[j].st << ' ' << mot[j].jos << ' ' << mot[j].dr << "\n\n";
  246. asem++;
  247. }
  248. }
  249.  
  250. if(asem != 1)
  251. fout << asem << ' ';
  252.  
  253. mot[i].vizitat = true;
  254. }
  255. }
  256.  
  257. return 0;
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement