Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stack>
- #include <iomanip>
- using namespace std;
- ifstream fin("cusaturi.in");
- ofstream fout("cusaturi.out");
- struct motive
- {
- int st, dr, jos, sus;
- int cate = 0;
- int cl, cc;
- bool vizitat = false;
- };
- motive mot[101];
- stack < pair < int, int > > s;
- int di[] = {-1, -1, 0, 1, 1, 1, 0, -1};
- int dj[] = {0, 1, 1, 1, 0, -1, -1, -1};
- int mat[101][101];
- int c, n, m;
- void FILL(int i, int j, int nr)
- {
- mot[nr].sus = i;
- mot[nr].jos = i;
- mot[nr].st = j;
- mot[nr].dr = j;
- s.push(make_pair(i, j));
- while(!s.empty())
- {
- i = s.top().first;
- j = s.top().second;
- mat[i][j] = nr;
- if(mot[nr].sus > i)
- mot[nr].sus = i;
- if(mot[nr].jos < i)
- mot[nr].jos = i;
- if(mot[nr].st > j)
- mot[nr].st = j;
- if(mot[nr].dr < j)
- mot[nr].dr = j;
- mot[nr].cate++;
- s.pop();
- for(int k = 0; k < 8; k++)
- {
- int nexti = i + di[k];
- int nextj = j + dj[k];
- if(mat[nexti][nextj] == -1)
- {
- mat[nexti][nextj] = nr;
- s.push(make_pair(nexti, nextj));
- }
- }
- }
- mot[nr].cl = mot[nr].jos - mot[nr].sus + 1;
- mot[nr].cc = mot[nr].dr - mot[nr].st + 1;
- }
- bool motEchi(motive &a, motive &b)
- {
- if(b.vizitat == true)
- return false;
- bool oke = true;
- if(a.cate != b.cate)
- return false;
- if(a.cl != b.cl || a.cc != b.cc)
- return false;
- //fout << a.sus + 1 << ' ' << a.st + 1<< ' ' << a.jos + 1<< ' ' << a.dr + 1<< '\n';
- //fout << b.sus + 1 << ' ' << b.st + 1 << ' ' << b.jos + 1 << ' ' << b.dr + 1 << "\n\n";
- for(int i = 0; i < a.cl; i++)
- {
- for(int j = 0; j < a.cc; j++)
- {
- if(mat[a.sus + i][a.st + j] != mat[b.sus + i][b.st + j])
- {
- oke = false;
- break;
- }
- }
- if(!oke)
- break;
- }
- if(!oke)
- {
- oke = true;
- for(int i = 0; i < a.cl; i++)
- {
- for(int j = 0; j < a.cc; j++)
- {
- if(mat[a.sus + i][a.st + j] != mat[b.sus + i][b.dr - j])
- {
- oke = false;
- break;
- }
- }
- if(!oke)
- break;
- }
- }
- else
- {
- b.vizitat = true;
- return true;
- }
- if(!oke)
- {
- oke = true;
- for(int i = a.cl - 1; i > -1; i--)
- {
- for(int j = 0; j < a.cc; j++)
- {
- if(mat[a.sus + i][a.st + j] != mat[b.jos - i][b.st + j])
- {
- oke = false;
- break;
- }
- }
- if(!oke)
- break;
- }
- }
- else
- {
- b.vizitat = true;
- return true;
- }
- if(!oke)
- {
- oke = true;
- for(int i = a.cl - 1; i > -1; i--)
- {
- for(int j = 0; j < a.cc; j++)
- {
- if(mat[a.sus + i][a.st + j] != mat[b.jos - i][b.dr + j])
- {
- oke = false;
- break;
- }
- }
- if(!oke)
- break;
- }
- }
- else
- {
- b.vizitat = true;
- return true;
- }
- if(!oke)
- return false;
- b.vizitat = true;
- return true;
- }
- int main()
- {
- fin >> c >> n >> m;
- char car;
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- fin >> car;
- if(car == 'X')
- mat[i][j] = -1;
- }
- }
- int cate = 0;
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- if(mat[i][j] == -1)
- {
- cate++;
- FILL(i, j, cate);
- }
- }
- }
- fout << cate << '\n';
- for(int i = 1; i <= cate; i++)
- {
- int asem = 1;
- if(mot[i].vizitat == false)
- {
- //fout << i << ' ' << mot[i].sus << ' ' << mot[i].st << ' ' << mot[i].jos << ' ' << mot[i].dr << '\n';
- for(int j = i + 1; j < cate; j++)
- {
- if(mot[j].vizitat == false && !motEchi(mot[i], mot[j]))
- {
- mot[j].vizitat = true;
- //fout << mot[j].sus << ' ' << mot[j].st << ' ' << mot[j].jos << ' ' << mot[j].dr << "\n\n";
- asem++;
- }
- }
- if(asem != 1)
- fout << asem << ' ';
- mot[i].vizitat = true;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement