洛谷 P2615 [NOIP2015 提高组] 神奇的幻方
更多...
#include <luogu.h>
|
static int | main (istream &cin, ostream &cout) |
|
洛谷 P2615 [NOIP2015 提高组] 神奇的幻方
在文件 luogu.h 第 413 行定义.
◆ main()
int luogu::P2615::main |
( |
istream & |
cin, |
|
|
ostream & |
cout |
|
) |
| |
|
static |
在文件 luogu.cpp 第 1274 行定义.
1277 memset(square, 0,
sizeof square);
1278 auto um = unordered_map<int, pair<int, int>>();
1280 square[0][n / 2] = 1;
1281 um[1] = make_pair(0, n / 2);
1282 for(
int k = 2; k <= n * n; k++) {
1283 auto [prev_x, prev_y] = um[k - 1];
1284 if(prev_x == 0 && prev_y != n - 1) {
1286 square[n - 1][prev_y + 1] = k;
1287 um[k] = make_pair(n - 1, prev_y + 1);
1288 }
else if(prev_y == n - 1 && prev_x != 0) {
1290 square[prev_x - 1][0] = k;
1291 um[k] = make_pair(prev_x - 1, 0);
1292 }
else if(prev_x == 0 && prev_y == n - 1) {
1294 square[1][prev_y] = k;
1295 um[k] = make_pair(1, prev_y);
1296 }
else if(prev_x != 0 && prev_y != n - 1) {
1298 if(square[prev_x - 1][prev_y + 1] == 0) {
1299 square[prev_x - 1][prev_y + 1] = k;
1300 um[k] = make_pair(prev_x - 1, prev_y + 1);
1302 square[prev_x + 1][prev_y] = k;
1303 um[k] = make_pair(prev_x + 1, prev_y);
1307 for(
int i = 0; i < n; i++) {
1308 for(
int j = 0; j < n; j++) {
1309 cout << square[i][j] <<
" ";
被这些函数引用 luogu::TEST().
该类的文档由以下文件生成: