Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <bitset>
- #include <queue>
- #define MAX 104
- #define NS 0101
- #define EV 1010
- using namespace std;
- ifstream fin("pereti.in");
- ofstream fout("pereti.out");
- int n, m;
- int di[5]= {-1, 0, +1, 0};
- int dj[5]= {0, +1,0, -1};
- queue<pair<int, int> > q;
- int a[MAX][MAX];
- int aux[MAX][MAX];
- void gard()
- {
- int i, j;
- for (j = 1; j <= m; j++)
- {
- if ((a[1][j] & 8) != 0)
- {
- a[0][j] = 2;
- }
- }
- for (j = 1; j <= m; j++)
- {
- if ((a[n][j] & 2) != 0)
- {
- a[n + 1][j] = 8;
- }
- }
- for (i = 1; i <= n; i++)
- {
- if ((a[i][1] & 1) != 0)
- {
- a[i][0] = 4;
- }
- }
- for (i = 1; i <= n; i++)
- {
- if ((a[i][m] & 4) != 0)
- {
- a[i][m + 1] = 1;
- }
- }
- }
- bool posibil(int i, int j)
- {
- if((i>0 && i<=n+1) && (j>0 && j<=m+1))
- {
- return true;
- }
- return false;
- }
- int FILL()
- {
- int nexti,nextj,cate=0;
- while(!q.empty())
- {
- int i=q.front().first;
- int j=q.front().second;
- q.pop();
- for(int k=0; k<4; k++)
- {
- nexti=i+di[k];
- nextj=j+dj[k];
- if(posibil(nexti,nextj)==true && aux[nexti][nextj]==0 && (!(a[nexti][nextj] & NS) || !(a[nexti][nextj] & EV)))
- {
- aux[nexti][nextj]+=1;
- q.push({nexti,nextj});
- cate+=1;
- }
- }
- q.pop();
- }
- return cate;
- }
- void algoritm()
- {
- fin>>n>>m;
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=m; j++)
- {
- fin>>a[i][j];
- }
- }
- fin.close();
- gard();
- for(int i=0; i<=n+1; i++)
- {
- if(a[0][i]==0)
- {
- q.push({0,i});
- }
- if(a[i][0]==0)
- {
- q.push({i,0});
- }
- }
- for(int i=0; i<=n+1; i++)
- {
- if(a[n+i][i]==0)
- {
- q.push({n+1,i});
- }
- if(a[i][m+1]==0)
- {
- q.push({i,m+1});
- }
- }
- int walls=FILL();
- int doors=0;
- }
- void afisari()
- {
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=m; j++)
- {
- fout<<aux[i][j]<<" ";
- }
- fout<<endl;
- }
- fout.close();
- }
- int main()
- {
- algoritm();
- afisari();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement