Iamtui1010

vacuum

Nov 9th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<fstream>
  4. #include<vector>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. const long N = 1e2+10;
  10.  
  11. using namespace std;
  12.  
  13. // Global variables: f1, f2, n, k, mat, squ
  14.  
  15. fstream f1, f2;
  16.  
  17. inline void openf()
  18. {
  19.     f1.open("xoanoc.inp", ios:: in);
  20.     f2.open("xoanoc.out", ios:: out);
  21. }
  22.  
  23. inline void closef()
  24. {
  25.     f1.close();
  26.     f2.close();
  27. }
  28.  
  29. long n, k, squ = 0;
  30. vector<vector<long>> mat(N), cam(N);
  31.  
  32. void data()
  33. {
  34.     f1.tie(0)->sync_with_stdio(0);
  35.     f2.tie(0)->sync_with_stdio(0);
  36.  
  37.     cin >> n >> k;
  38.     for (long i = 1; i-1 != n; ++i)
  39.     {
  40.         cam[i].resize(n+1, 0);
  41.         mat[i].push_back(0);
  42.         for (long j = 1; j-1 != n; ++j)
  43.         {
  44.             bool x;
  45.             cin >> x;
  46.             if (!x)
  47.                 ++squ;
  48.             mat[i].push_back(x);
  49.         }
  50.     }
  51. }
  52.  
  53. long lo1, lo2;
  54.  
  55. void process()
  56. {
  57.     bool neg = 0;
  58.     squ--;
  59.     if ((k/squ) % 2 == 1)
  60.         neg = 1;
  61.  
  62.     long step = k % squ;
  63.  
  64.     if (neg)
  65.         step = squ - step;
  66.  
  67.     // Turn on
  68.  
  69.     long i = 1, j = 1, met = 0;
  70.     while (step >= 0)
  71.     {
  72.         lo1 = i; lo2 = j;
  73.         cam[i][j] = 1;
  74.         if (!mat[i][j])
  75.         {
  76.             mat[i][j] = 1;
  77.             --step;
  78.         }
  79.  
  80.         if (met == 4)
  81.             met = 0;
  82.  
  83.         if (met == 0)
  84.         {
  85.             ++j;
  86.             if (j == n+1 || cam[i][j])
  87.             {
  88.                 --j;
  89.                 ++i;
  90.                 ++met;
  91.             }
  92.             continue;
  93.         }
  94.         if (met == 1)
  95.         {
  96.             ++i;
  97.             if (i == n+1 || cam[i][j])
  98.             {
  99.                 --i;
  100.                 --j;
  101.                 ++met;
  102.             }
  103.             continue;
  104.         }
  105.         if (met == 2)
  106.         {
  107.             --j;
  108.             if (j == 0 || cam[i][j])
  109.             {
  110.                 ++j;
  111.                 --i;
  112.                 ++met;
  113.             }
  114.             continue;
  115.         }
  116.         if (met == 3)
  117.         {
  118.             --i;
  119.             if (i == 0 || cam[i][j])
  120.             {
  121.                 ++i;
  122.                 ++j;
  123.                 ++met;
  124.             }
  125.         }
  126.     }
  127. }
  128.  
  129. void view()
  130. {
  131.     cout<< lo1 << ' ' << lo2 << nln;
  132. }
  133.  
  134. int main()
  135. {
  136.     openf();
  137.     data();
  138.     process();
  139.     view();
  140.     closef();
  141.     return 0;
  142. }
  143.  
Advertisement
Add Comment
Please, Sign In to add comment