Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ft first
- #define sc second
- using namespace std;
- vector<pair<int,int>> A;
- vector<pair<int,int>> B;
- vector<pair<int,int>> C;
- char tab[125][125];
- long long nwd(long long a, long long b)
- {
- if (b==0) {return a;}
- return nwd(b,a%b);
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n,m,X,Y,g,kx,ky,xcurr,ycurr,ile=0;
- char ch;
- bool ok;
- cin>>n>>m;
- A.clear();
- B.clear();
- C.clear();
- for (int y=0;y<=m;y++)
- {
- for (int x=0;x<=n;x++)
- {
- cin>>ch;
- cout << ch;
- tab[y][x]=ch;
- if (ch=='A')
- {
- A.push_back({y,x});
- }
- else if (ch=='B')
- {
- B.push_back({y,x});
- }
- else if (ch=='C')
- {
- C.push_back({y,x});
- }
- }
- cout << "\n";
- }
- for (int i=0;i<A.size();i++)
- {
- for (int j=0;j<B.size();j++)
- {
- ok=1;
- X=abs(A[i].sc-B[j].sc);
- Y=abs(A[i].ft-B[j].ft);
- g=nwd(X,Y);
- X/=g;
- Y/=g;
- kx=1;
- if (B[j].sc<A[i].sc) {kx=-1;}
- ky=1;
- if (B[j].ft<A[i].ft) {ky=-1;}
- xcurr=A[i].sc;
- ycurr=A[i].ft;
- for (int z=0;z<g-1;z++)
- {
- xcurr+=(X*kx);
- ycurr+=(Y*ky);
- if (tab[ycurr][xcurr]=='C')
- {
- ok=0;
- break;
- }
- }
- ile+=ok;
- }
- }
- cout<<ile;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment