problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
luogu::P5731类 参考

洛谷 P5731 【深基5.习6】蛇形方阵 更多...

#include <luogu.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 
static pair< int, int > move_forward (int dir, int current_x, int current_y)
 

详细描述

洛谷 P5731 【深基5.习6】蛇形方阵

在文件 luogu.h455 行定义.

成员函数说明

◆ main()

int luogu::P5731::main ( istream &  cin,
ostream &  cout 
)
static

< Direction 0 = R, 1 = D, 2 = L, 3 = U

在文件 luogu.cpp1506 行定义.

1506 {
1507 int n;
1508 cin >> n;
1509 int square[9][9] = {};
1510 int dir = 0;
1511 int current_x = 0;
1512 int current_y = 0;
1513 for(int i = 1; i <= n * n; i++) {
1514 square[current_x][current_y] = i;
1515 auto [next_x, next_y] = move_forward(dir, current_x, current_y);
1516 if(next_x < 0 || next_x >= n || next_y < 0 || next_y >= n || square[next_x][next_y] != 0) {
1517 dir = (dir + 1) % 4;
1518 }
1519 const auto next = move_forward(dir, current_x, current_y);
1520 current_x = next.first;
1521 current_y = next.second;
1522 }
1523 for(int i = 0; i < n; i++) {
1524 for(int j = 0; j < n; j++) {
1525 cout << setw(3) << right << setfill(' ') << square[i][j];
1526 }
1527 cout << endl;
1528 }
1529 return 0;
1530 }
static pair< int, int > move_forward(int dir, int current_x, int current_y)
Definition: luogu.cpp:1532

引用了 move_forward() , 以及 acwing::acwing1929::right.

被这些函数引用 luogu::TEST().

◆ move_forward()

pair< int, int > luogu::P5731::move_forward ( int  dir,
int  current_x,
int  current_y 
)
static

< R

< D

< L

< U

在文件 luogu.cpp1532 行定义.

1532 {
1533 int next_x = current_x;
1534 int next_y = current_y;
1535 switch(dir) {
1536 case 0:
1537 next_y++;
1538 break;
1539 case 1:
1540 next_x++;
1541 break;
1542 case 2:
1543 next_y--;
1544 break;
1545 case 3:
1546 next_x--;
1547 break;
1548 }
1549 return make_pair(next_x, next_y);
1550 }

被这些函数引用 main().


该类的文档由以下文件生成: