Advertisement
Nita_Cristian

ai al meu de 60 pct

Feb 24th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("ai.in");
  6. ofstream fout("ai.out");
  7.  
  8. int n, k, a, b, m[1010][1010], v[1010][1010], d_x, d_y, c, y, rez[1010][1010];
  9. int tx, ty, s1x, s1y, s2x, s2y, r1x, r1y, r2x, r2y;
  10. int di[4] = {-1, 0, 1, 0};
  11. int dj[4] = {0, 1, 0, -1};
  12. vector<pair<int,int>> d1, d2;
  13.  
  14. void lee(int i, int j)
  15. {
  16.     queue<pair<int, int>> q;
  17.     memset(rez, 0, sizeof(rez));
  18.     rez[i][j] = 1;
  19.     q.push({i, j});
  20.  
  21.     while(!q.empty())
  22.     {
  23.         i = q.front().first;
  24.         j = q.front().second;
  25.         q.pop();
  26.  
  27.         for(int k = 0; k < 4; k++)
  28.         {
  29.             int ni = i + di[k];
  30.             int nj = j + dj[k];
  31.             if(m[ni][nj] == 0 && rez[ni][nj] == 0)
  32.             {
  33.                 rez[ni][nj] = rez[i][j] + 1;
  34.                 q.push({ni, nj});
  35.             }
  36.         }
  37.     }
  38. }
  39.  
  40. int lmax_lin(int i)
  41. {
  42.     int lcrt = 0, lmax = INT_MIN;
  43.     for(int j = 1; j <= n; j++)
  44.     {
  45.         if(m[i][j] == -1)
  46.             lcrt++;
  47.         else
  48.         {
  49.             lmax = max(lcrt, lmax);
  50.             lcrt = 0;
  51.         }
  52.     }
  53.     lmax = max(lcrt, lmax);
  54.  
  55.     return lmax;
  56. }
  57.  
  58. int lmax_col(int j)
  59. {
  60.     int lcrt = 0, lmax = INT_MIN;
  61.     for(int i = 1; i <= n; i++)
  62.     {
  63.         if(m[i][j] == -1)
  64.             lcrt++;
  65.         else
  66.         {
  67.             lmax = max(lcrt, lmax);
  68.             lcrt = 0;
  69.         }
  70.     }
  71.     lmax = max(lcrt, lmax);
  72.     return lmax;
  73. }
  74.  
  75. void gard(int n, int k)
  76. {
  77.     for(int i = 0; i <= n+1; i++)
  78.         m[i][0] = m[i][k+1] = -1;
  79.     for(int j = 0; j <= k+1; j++)
  80.         m[0][j] = m[n+1][j] = -1;
  81. }
  82.  
  83. void pct_dr(int tx, int sx, int sy, vector<pair<int,int>> &d)
  84. {
  85.     int d_x = abs(tx - sx);
  86.     int d_y = abs(ty - sy);
  87.     int c = __gcd(d_x, d_y);
  88.  
  89.     d_x /= c;
  90.     d_y /= c;
  91.  
  92.     if(sx < tx)
  93.         for(int x = sx; x != tx; x += d_x)
  94.             y += d_y, v[x][y] = 1, d.push_back({x,y});
  95.     else
  96.     {
  97.         y = sy;
  98.         for(int x = sx; x != tx; x -= d_x)
  99.             d.push_back({x,y}), v[x][y] = 1, y -= d_y;
  100.     }
  101. }
  102.  
  103. int dreapta_robot(vector<pair<int,int>> d)
  104. {
  105.     int minim = INT_MAX;
  106.     for(int i = 0; i < d.size(); i++)
  107.     {
  108.         int a = rez[d[i].first][d[i].second];
  109.         if(a && a < minim)
  110.             minim = a;
  111.     }
  112.     return minim-1;
  113. }
  114.  
  115. int main()
  116. {
  117.     fin >> n;
  118.     fin >> tx >> ty >> s1x >> s1y >> s2x >> s2y >> r1x >> r1y >> r2x >> r2y;
  119.     gard(n, n);
  120.  
  121.     fin >> k;
  122.     for (int i = 1; i <= k; i++)
  123.         fin >> a >> b, m[a][b] = -1;
  124.  
  125.     int lz = INT_MIN;
  126.     for(int i = 1; i <= n; i++)
  127.         lz = max(lz, lmax_lin(i));
  128.     for(int j = 1; j <= n; j++)
  129.         lz = max(lz, lmax_col(j));
  130.  
  131.     fout << lz << '\n';
  132.  
  133.     m[tx][ty] = -1;
  134.  
  135.     pct_dr(tx, s1x, s1y, d1);
  136.     pct_dr(tx, s2x, s2y, d2);
  137.  
  138.     lee(r1x, r1y);
  139.  
  140.     int dr1_r1 = dreapta_robot(d1);
  141.     //cout << dr1_r1 << ' ' ;
  142.     int dr2_r1 = dreapta_robot(d2);
  143.     //cout << dr2_r1 << '\n';
  144.     lee(r2x, r2y);
  145.  
  146.     int dr1_r2 = dreapta_robot(d1);
  147.     //cout << dr1_r2 << ' ' ;
  148.     int dr2_r2 = dreapta_robot(d2);
  149.     //cout << dr2_r2 << '\n' ;
  150.  
  151.     int m1 = max(dr1_r1, dr2_r2);
  152.     int m2 = max(dr2_r1, dr1_r2);
  153.  
  154.     if(m1 < m2)
  155.         fout << m1;
  156.     else
  157.         fout << m2;
  158.  
  159.  
  160.     fin.close();
  161.     fout.close();
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement