problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 属性 | 所有成员列表
acwing::acwing1929::Solution类 参考

#include <acwing.h>

Public 成员函数

unsigned int count_reflect (direction d, unsigned int x, unsigned int y)
 获取反射的次数 更多...
 
unsigned(* get_record (direction d))[1000]
 获取记录类型 更多...
 
int main (istream &cin, ostream &cout)
 

Private 属性

unsigned int down_map [1000][1000] = {0}
 在每格向下时可以被反射的次数 更多...
 
unsigned int left_map [1000][1000] = {0}
 在每格向左时可以被反射的次数 更多...
 
unsigned short m {}
 列数 更多...
 
char mirrors [1000][1000] = {0}
 镜子 更多...
 
unsigned short n {}
 行数 更多...
 
unsigned int right_map [1000][1000] = {0}
 在每格向右时可以被反射的次数 更多...
 
unsigned int up_map [1000][1000] = {0}
 在每格向上时可以被反射的次数 更多...
 

详细描述

在文件 acwing.h581 行定义.

成员函数说明

◆ count_reflect()

unsigned int acwing::acwing1929::Solution::count_reflect ( direction  d,
unsigned int  x,
unsigned int  y 
)

获取反射的次数

参数
d方向
x横坐标
y纵坐标
返回
在(x,y)以d方向前进的光距离离开剩下的反射次数

在文件 acwing.cpp1605 行定义.

1605 {
1606 if(x == 0 || y == 0 || x == n - 1 || y == m - 1) {
1607 unsigned int count = 0;
1608 int current_x = x;
1609 int current_y = y;
1610 direction current_d = d;
1611 auto path = unordered_set<step, step_hash, step_equal>();
1612 while(0 <= current_x && current_x < n && 0 <= current_y && current_y < m) {
1613 auto s = step(current_d, current_x, current_y);
1614 if(!path.contains(s)) {
1615 path.insert(s);
1616 } else {
1617 return -1;
1618 }
1619
1620 const auto *record = get_record(d);
1621 if((*record)[x][y] != 0) {
1622 return count + (*record)[x][y];
1623 }
1624 current_d = reflect(current_d, mirrors[current_x][current_y]);
1625 count++;
1626 (*get_record(!current_d))[current_x][current_y] = count;
1627 switch(current_d) {
1628 case left: {
1629 current_y--;
1630 break;
1631 }
1632 case right: {
1633 current_y++;
1634 break;
1635 }
1636 case up: {
1637 current_x--;
1638 break;
1639 }
1640 case down: {
1641 current_x++;
1642 break;
1643 }
1644 }
1645 }
1646 return count;
1647 }
1648 return -1;
1649 }
direction reflect(direction d, char mirror)
方向经过镜子反射后的变化
Definition: acwing.cpp:1669
char mirrors[1000][1000]
镜子
Definition: acwing.h:584
unsigned short n
行数
Definition: acwing.h:594
unsigned(* get_record(direction d))[1000]
获取记录类型
Definition: acwing.cpp:1651
unsigned short m
列数
Definition: acwing.h:596

引用了 acwing::acwing1929::down, get_record(), acwing::acwing1929::left, m, mirrors, n, acwing::acwing1929::reflect(), acwing::acwing1929::right , 以及 acwing::acwing1929::up.

被这些函数引用 main().

◆ get_record()

unsigned int(* acwing::acwing1929::Solution::get_record ( direction  d) )[1000]

获取记录类型

参数
d方向
返回
方向对应的记录

在文件 acwing.cpp1651 行定义.

1651 {
1652 switch(d) {
1653 case left: {
1654 return &left_map;
1655 }
1656 case right: {
1657 return &right_map;
1658 }
1659 case up: {
1660 return &up_map;
1661 }
1662 case down: {
1663 return &down_map;
1664 }
1665 }
1666 return nullptr;
1667 }
unsigned int right_map[1000][1000]
在每格向右时可以被反射的次数
Definition: acwing.h:588
unsigned int down_map[1000][1000]
在每格向下时可以被反射的次数
Definition: acwing.h:592
unsigned int up_map[1000][1000]
在每格向上时可以被反射的次数
Definition: acwing.h:590
unsigned int left_map[1000][1000]
在每格向左时可以被反射的次数
Definition: acwing.h:586

引用了 acwing::acwing1929::down, acwing::acwing1929::left, acwing::acwing1929::right , 以及 acwing::acwing1929::up.

被这些函数引用 count_reflect().

◆ main()

int acwing::acwing1929::Solution::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing.cpp1581 行定义.

1581 {
1582 cin >> n >> m;
1583 for(unsigned short i = 0; i < n; i++) {
1584 for(unsigned short j = 0; j < m; j++) {
1585 cin >> mirrors[i][j];
1586 }
1587 }
1588 int maximum = -1;
1589 for(unsigned short j = 0; j < m; j++) {
1590 maximum = max(maximum, static_cast<int>(count_reflect(down, 0, j)));
1591 }
1592 for(unsigned short j = 0; j < m; j++) {
1593 maximum = max(maximum, static_cast<int>(count_reflect(up, n - 1, j)));
1594 }
1595 for(unsigned short i = 0; i < n; i++) {
1596 maximum = max(maximum, static_cast<int>(count_reflect(right, i, 0)));
1597 }
1598 for(unsigned short i = 0; i < n; i++) {
1599 maximum = max(maximum, static_cast<int>(count_reflect(left, i, m - 1)));
1600 }
1601 cout << maximum;
1602 return 0;
1603 }
unsigned int count_reflect(direction d, unsigned int x, unsigned int y)
获取反射的次数
Definition: acwing.cpp:1605

引用了 count_reflect(), acwing::acwing1929::down, acwing::acwing1929::left, m, mirrors, n, acwing::acwing1929::right , 以及 acwing::acwing1929::up.

类成员变量说明

◆ down_map

unsigned int acwing::acwing1929::Solution::down_map[1000][1000] = {0}
private

在每格向下时可以被反射的次数

在文件 acwing.h592 行定义.

◆ left_map

unsigned int acwing::acwing1929::Solution::left_map[1000][1000] = {0}
private

在每格向左时可以被反射的次数

在文件 acwing.h586 行定义.

◆ m

unsigned short acwing::acwing1929::Solution::m {}
private

列数

在文件 acwing.h596 行定义.

被这些函数引用 count_reflect() , 以及 main().

◆ mirrors

char acwing::acwing1929::Solution::mirrors[1000][1000] = {0}
private

镜子

在文件 acwing.h584 行定义.

被这些函数引用 count_reflect() , 以及 main().

◆ n

unsigned short acwing::acwing1929::Solution::n {}
private

行数

在文件 acwing.h594 行定义.

被这些函数引用 count_reflect() , 以及 main().

◆ right_map

unsigned int acwing::acwing1929::Solution::right_map[1000][1000] = {0}
private

在每格向右时可以被反射的次数

在文件 acwing.h588 行定义.

◆ up_map

unsigned int acwing::acwing1929::Solution::up_map[1000][1000] = {0}
private

在每格向上时可以被反射的次数

在文件 acwing.h590 行定义.


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