Skip to content

Instantly share code, notes, and snippets.

@ro0opf
Created March 1, 2019 08:56
Show Gist options
  • Save ro0opf/7ad8f0e0274a6c5dec7740c092d02cb3 to your computer and use it in GitHub Desktop.
Save ro0opf/7ad8f0e0274a6c5dec7740c092d02cb3 to your computer and use it in GitHub Desktop.
1913
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
#include <map>
#include <stack>
#include <functional>
#include <set>
#include <math.h>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <cstdio>
#include <sstream>
#define ll long long int
#define ld long double
#define fr(i, a, b) for(int i = a; i < b; i++)
#define frb(i, a, b) for(int i = a; i >= b; i--)
#define sq(x) ((x) * (x))
#define PI ( acos(-1.0) )
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define px first
#define py second
using namespace std;
typedef vector<vector<int>> mat;
int a, b;
int dt[1000][1000];
void init() {
cin >> a >> b;
}
int xar[4] = { 0,1,0, -1 };
int yar[4] = { 1,0, -1, 0 };
void solve() {
int v = a * a;
int i = 0;
int j = 0;
pii pos;
int dir = 0;
while (!(i == a / 2 && j == a / 2)) {
if (v == b) {
pos.first = i;
pos.second = j;
}
dt[i][j] = v--;
int ti = i + xar[dir];
int tj = j + yar[dir];
if (ti >= a || ti < 0 || tj >= a || tj < 0 || dt[ti][tj]) {
dir = (dir + 1) % 4;
i += xar[dir];
j += yar[dir];
}
else {
i = ti;
j = tj;
}
}
dt[i][j] = 1;
fr(y, 0, a) {
fr(x, 0, a) {
cout << dt[x][y] << " ";
}
cout << "\n";
}
cout << pos.second + 1 << " " << pos.first + 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
init();
solve();
//system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment