Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- short int n,m,p,A[102][102],ntcs,npsca; /// ntcs = numar total cabine sigure; npsca = numar portale situate in cabine accesibile
- short int di[8]={-1, 0,1,0,-1,-1,-1,1}, /// directia i (N, V(E), S, V, N-V, N-E, S-V, S-E)
- dj[8]={ 0,-1,0,1,-1, 1,-1,1}; /// directia j
- void Fill(short int i,short int j) /// Functia de umplere cu 3
- {
- if(A[i][j]==2)
- ++npsca;
- if(A[i][j]!=1&&A[i][j]!=3)
- {
- A[i][j]=3;
- if(i>1) Fill(i-1,j); /// N
- if(j>1) Fill(i,j-1); /// V
- if(i<n) Fill(i+1,j); /// S
- if(j<m) Fill(i,j+1); /// E
- if(i>1&&j>1) Fill(i-1,j-1); /// N-V
- if(i>1&&j<m) Fill(i-1,j+1); /// N-E
- if(i<n&&j>1) Fill(i+1,j-1); /// S-V
- if(i<n&&j<m) Fill(i+1,j+1); /// S-E
- }
- }
- int main()
- {
- ifstream fin("amongus.in");
- fin>>p;
- fin>>n>>m;
- for(int i=1;i<=n;++i)
- for(int j=1;j<=m;++j)
- fin>>A[i][j];
- ofstream fout("amongus.out");
- if(A[1][1]==1)
- {
- fout<<"misiune esuata";
- return 0;
- }
- if(p==1)
- {
- for(short int i=1;i<=n;++i)
- for(short int j=1;j<=m;++j)
- if(A[i][j]==0)
- ++ntcs;
- fout<<ntcs;
- return 0;
- }
- Fill(1,1);
- if(p==2)
- for(short int i=1;i<=n;++i,fout<<'\n')
- for(short int j=1;j<=m;++j)
- fout<<A[i][j]<<' ';
- else
- fout<<npsca;
- return 0;
- }
Add Comment
Please, Sign In to add comment