Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<queue>
- using namespace std;
- ifstream fin("VISUL.in");
- ofstream fout("VISUL.out");
- int a[25][25];
- queue<pair<int, int> >q;
- int di[3]= {1, 1, 1};
- int dj[3]= {-1, 0, 1};
- int maxim=1;
- parcurgere(int i, int j)
- {
- int k, nexti, nextj, contor;
- q.push({i, j});
- a[i][j]=1;
- while(!q.empty())
- {
- i=q.front().first;
- j=q.front().second;
- q.pop();
- contor=0;
- for(k=0; k<3; k++)
- {
- nexti=i+di[k];
- nextj=j+dj[k];
- if( (k==0 || k==2) && a[nexti][nextj]==-2 || k==1 && a[nexti][nextj]==0)
- {
- q.push({nexti, nextj});
- if(contor==0)
- {
- a[nexti][nextj]=a[i][j];
- contor++;
- }
- else
- {
- maxim++;
- a[nexti][nextj]=maxim;
- contor++;
- }
- }
- }
- }
- return maxim;
- }
- int main()
- {
- int i, j, n, coloana, nr, x, y;
- fin>>n>>coloana>>nr;
- for(i=1; i<=nr; i++)
- {
- fin>>x>>y;
- a[x][y]=-2;
- }
- for(j=0; j<=n+1; j++)
- {
- a[0][j]=a[n+1][j]=-1;
- }
- for(i=0; i<=n+1; i++)
- {
- a[i][0]=a[i][n+1]=-1;
- }
- parcurgere(1, coloana);
- fout<<maxim;
- fout<<"\n";
- for(i=0; i<=n+1; i++)
- {
- for(j=0; j<=n+1; j++)
- {
- fout<<a[i][j]<<" ";
- }
- fout<<"\n";
- }
- fin.close();
- fout.close();
- return 0;
- /*5 5 7
- 1 1
- 2 2
- 2 4
- 3 4
- 3 5
- 4 2
- 4 3*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement