Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<queue>
  4. #include<cstring>
  5. using namespace std;
  6. ifstream fin("pereti.in");
  7. ofstream fout("pereti.out");
  8. int di[4]={-1, 0,1, 0};
  9. int dj[4]={0,1,0,-1};
  10.  
  11. int a[115][115];
  12. int b[115][115];
  13. queue<pair<int, int> >q;
  14.  
  15. int Fill(int i, int j)
  16. {
  17. int k,nexti,nextj,nr;
  18. int zid=0;
  19. q.push({i,j});
  20. b[i][j]=-1;
  21.  
  22. while(!q.empty())
  23. {
  24. i=q.front().first;
  25. j=q.front().second;
  26. q.pop();
  27.  
  28. nr=16;
  29. for(k=0;k<4;k++)
  30. {
  31. nr/=2;
  32. nexti=i+di[k];
  33. nextj=j+dj[k];
  34. if(b[nexti][nextj]!=-1)
  35. {
  36. if((a[i][j] & nr)==0)
  37. {
  38. q.push({nexti, nextj});
  39. b[nexti][nextj]=-1;
  40. }
  41. else
  42. {
  43. zid++;
  44. }
  45. }
  46. }
  47. }
  48.  
  49. return zid;
  50.  
  51. }
  52.  
  53.  
  54. int main()
  55. {
  56. int n,m,i,j;
  57. fin>>n>>m;
  58. for(i=2;i<=n+1;i++)
  59. {
  60. for(j=2;j<=m+1;j++)
  61. {
  62. fin>>a[i][j];
  63. }
  64. }
  65. for(j=0;j<=m+3;j++)
  66. {
  67. a[0][j]=a[n+3][j]=-1;
  68. }
  69. for(i=0;i<=n+3;i++)
  70. {
  71. a[i][0]=a[i][m+3]=-1;
  72. }
  73. for(j=1;j<=m+1;j++)
  74. {
  75. a[1][j]=8;
  76. a[n+1][j]=2;
  77. }
  78. for(i=1;i<=n+1;i++)
  79. {
  80. a[i][1]=1;
  81. a[i][m+1]=4;
  82. }
  83.  
  84. memset(b,0,sizeof(0));
  85.  
  86. int pereti;
  87. pereti=Fill(1,1);
  88. fout<<pereti;
  89.  
  90. fin.close();
  91. fout.close();
  92. return 0;
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement