Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream in ("magic.in");
- ofstream out ("magic.out");
- int getvalue(pair<int,int> a, int n){
- int x = a.first;
- int y = a.second;
- int x2 = (n / 2);
- int y2 = - (n / 2);
- int value = 1;
- while(x2 + y2 != (x + y)){
- x2++;
- y2++;
- value += n;
- }
- while(x2 != x && y2 != y){
- y2++;
- x2--;
- value++;
- }
- return value;
- }
- pair<int,int> realpos(pair<int, int> a, int n){
- int x = a.first;
- int y = a.second;
- if((x + y) % 2 == 0)
- return {x, y};
- else{
- if(y < x) {
- if(y < (n - x))
- return {x, y + n};
- else
- return {x - n, y};
- } else {
- if(y < (n - x))
- return {x + n, y};
- else
- return {x, y - n};
- }
- }
- }
- int main()
- {
- int n;
- in >> n;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- out << getvalue(realpos({i, j}, n), n) << " ";
- }
- out << '\n';
- }
- int N, l, c;
- in >> N >> l >> c;
- out << getvalue(realpos({l - 1, c - 1}, N), N);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement