Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, a[100][100], max=-1;
- cin >> n;
- // fill nearby cells
- int i = 0, j = -1, count = 0;
- while (count < n*n) {
- while (j < n - 1 && !a[i][j+1])
- a[i][++j] = ++count; // право
- while (i < n - 1 && !a[i+1][j])
- a[++i][j] = ++count; // низ
- while (j > 0 && !a[i][j-1])
- a[i][--j] = ++count; // лево
- while (i > 0 && !a[i-1][j])
- a[--i][j] = ++count; // верх
- }
- int s=0, min=1000000000, minx=100000000;
- for (int x = 0; x<n*n; x++) {
- s=0;
- for (int i = 0; i<n; i++) {
- int j = i;
- s+=(a[i][j]+x)%841;
- } if (s<min) min=s, minx=x;
- } cout << minx << " " << min;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement