willy108

ziplines

Sep 5th, 2022
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ft first
  3. #define sc second
  4. using namespace std;
  5. vector<pair<int,int>> A;
  6. vector<pair<int,int>> B;
  7. vector<pair<int,int>> C;
  8. char tab[125][125];
  9.  
  10. long long nwd(long long a, long long b)
  11. {
  12.   if (b==0) {return a;}
  13.   return nwd(b,a%b);
  14. }
  15.  
  16. int main()
  17. {
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0);
  20. cout.tie(0);
  21.  
  22. int n,m,X,Y,g,kx,ky,xcurr,ycurr,ile=0;
  23. char ch;
  24. bool ok;
  25. cin>>n>>m;
  26.  
  27. A.clear();
  28. B.clear();
  29. C.clear();
  30.  
  31. for (int y=0;y<=m;y++)
  32. {
  33.   for (int x=0;x<=n;x++)
  34.   {
  35.     cin>>ch;
  36.     cout << ch;
  37.     tab[y][x]=ch;
  38.     if (ch=='A')
  39.     {
  40.       A.push_back({y,x});
  41.     }
  42.     else if (ch=='B')
  43.     {
  44.       B.push_back({y,x});
  45.     }
  46.     else if (ch=='C')
  47.     {
  48.       C.push_back({y,x});
  49.     }
  50.   }
  51.   cout << "\n";
  52. }
  53.  
  54. for (int i=0;i<A.size();i++)
  55. {
  56.   for (int j=0;j<B.size();j++)
  57.   {
  58.     ok=1;
  59.     X=abs(A[i].sc-B[j].sc);
  60.     Y=abs(A[i].ft-B[j].ft);
  61.     g=nwd(X,Y);
  62.     X/=g;
  63.     Y/=g;
  64.  
  65.     kx=1;
  66.     if (B[j].sc<A[i].sc) {kx=-1;}
  67.  
  68.     ky=1;
  69.     if (B[j].ft<A[i].ft) {ky=-1;}
  70.  
  71.     xcurr=A[i].sc;
  72.     ycurr=A[i].ft;
  73.  
  74.     for (int z=0;z<g-1;z++)
  75.     {
  76.       xcurr+=(X*kx);
  77.       ycurr+=(Y*ky);
  78.  
  79.       if (tab[ycurr][xcurr]=='C')
  80.       {
  81.         ok=0;
  82.         break;
  83.       }
  84.     }
  85.  
  86.     ile+=ok;
  87.   }
  88. }
  89.  
  90. cout<<ile;
  91.  
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment