Advertisement
Zuneve

11 class final 111

Dec 16th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n, a[100][100], max=-1;
  7. cin >> n;
  8.  
  9. // fill nearby cells
  10. int i = 0, j = -1, count = 0;
  11. while (count < n*n) {
  12. while (j < n - 1 && !a[i][j+1])
  13. a[i][++j] = ++count; // право
  14. while (i < n - 1 && !a[i+1][j])
  15. a[++i][j] = ++count; // низ
  16. while (j > 0 && !a[i][j-1])
  17. a[i][--j] = ++count; // лево
  18. while (i > 0 && !a[i-1][j])
  19. a[--i][j] = ++count; // верх
  20. }
  21. int s=0, min=1000000000, minx=100000000;
  22. for (int x = 0; x<n*n; x++) {
  23. s=0;
  24. for (int i = 0; i<n; i++) {
  25. int j = i;
  26. s+=(a[i][j]+x)%841;
  27. } if (s<min) min=s, minx=x;
  28. } cout << minx << " " << min;
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement