Guest User

Untitled

a guest
Oct 22nd, 2019
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<fstream>
  3. #include<queue>
  4. using namespace std;
  5. ifstream fin("VISUL.in");
  6. ofstream fout("VISUL.out");
  7.  
  8. int a[25][25];
  9. queue<pair<int, int> >q;
  10. int di[3]= {1, 1, 1};
  11. int dj[3]= {-1, 0, 1};
  12.  
  13. int maxim=1;
  14.  
  15. parcurgere(int i, int j)
  16. {
  17. int k, nexti, nextj, contor;
  18. q.push({i, j});
  19. a[i][j]=1;
  20.  
  21. while(!q.empty())
  22. {
  23. i=q.front().first;
  24. j=q.front().second;
  25. q.pop();
  26. contor=0;
  27.  
  28. for(k=0; k<3; k++)
  29. {
  30. nexti=i+di[k];
  31. nextj=j+dj[k];
  32.  
  33. if( (k==0 || k==2) && a[nexti][nextj]==-2 || k==1 && a[nexti][nextj]==0)
  34. {
  35. q.push({nexti, nextj});
  36. if(contor==0)
  37. {
  38. a[nexti][nextj]=a[i][j];
  39. contor++;
  40. }
  41. else
  42. {
  43. maxim++;
  44. a[nexti][nextj]=maxim;
  45. contor++;
  46. }
  47. }
  48. }
  49.  
  50. }
  51. return maxim;
  52. }
  53.  
  54. int main()
  55. {
  56. int i, j, n, coloana, nr, x, y;
  57. fin>>n>>coloana>>nr;
  58. for(i=1; i<=nr; i++)
  59. {
  60. fin>>x>>y;
  61. a[x][y]=-2;
  62. }
  63.  
  64. for(j=0; j<=n+1; j++)
  65. {
  66. a[0][j]=a[n+1][j]=-1;
  67. }
  68. for(i=0; i<=n+1; i++)
  69. {
  70. a[i][0]=a[i][n+1]=-1;
  71. }
  72.  
  73.  
  74. parcurgere(1, coloana);
  75. fout<<maxim;
  76. fout<<"\n";
  77.  
  78. for(i=0; i<=n+1; i++)
  79. {
  80. for(j=0; j<=n+1; j++)
  81. {
  82. fout<<a[i][j]<<" ";
  83. }
  84. fout<<"\n";
  85. }
  86.  
  87. fin.close();
  88. fout.close();
  89. return 0;
  90.  
  91. /*5 5 7
  92. 1 1
  93. 2 2
  94. 2 4
  95. 3 4
  96. 3 5
  97. 4 2
  98. 4 3*/
  99.  
  100.  
  101. }
RAW Paste Data