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

AcWing 1960. 闪烁 更多...

#include <acwing.h>

Public 成员函数

unsigned int compress (const bool *) const
 
bool * decompress (unsigned int status) const
 
unsigned int get_next (unsigned int status)
 
int main (istream &, ostream &)
 

Private 属性

int fsm [1<< 16] = {}
 
unsigned int n {}
 

详细描述

AcWing 1960. 闪烁

在文件 acwing.h431 行定义.

成员函数说明

◆ compress()

unsigned int acwing::acwing1960::compress ( const bool *  bulbs) const

在文件 acwing.cpp1184 行定义.

1184 {
1185 int status = 0;
1186 for(int i = 0; i < n; i++) {
1187 status += static_cast<int>(bulbs[i]);
1188 status <<= 1;
1189 }
1190 status >>= 1;
1191 return status;
1192 }
unsigned int n
Definition: acwing.h:434

引用了 n.

被这些函数引用 get_next().

◆ decompress()

bool * acwing::acwing1960::decompress ( unsigned int  status) const

在文件 acwing.cpp1175 行定义.

1175 {
1176 auto *const bulbs = new bool[n];
1177 for(int i = n - 1; i >= 0; i--) {
1178 bulbs[i] = (status & 1) != 0U;
1179 status >>= 1;
1180 }
1181 return bulbs;
1182 }

引用了 n.

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

◆ get_next()

unsigned int acwing::acwing1960::get_next ( unsigned int  status)

在文件 acwing.cpp1155 行定义.

1155 {
1156 if(fsm[status] >= 0) {
1157 return fsm[status];
1158 }
1159 const bool *bulbs = decompress(status);
1160 auto *const next_bulbs = new bool[n];
1161 for(int i = 0; i < n; i++) {
1162 if(bulbs[(i - 1 + n) % n]) {
1163 next_bulbs[i] = !bulbs[i];
1164 } else {
1165 next_bulbs[i] = bulbs[i];
1166 }
1167 }
1168 const int next_status = compress(next_bulbs);
1169 fsm[status] = next_status;
1170 delete[] next_bulbs;
1171 delete[] bulbs;
1172 return next_status;
1173 }
bool * decompress(unsigned int status) const
Definition: acwing.cpp:1175
unsigned int compress(const bool *) const
Definition: acwing.cpp:1184
int fsm[1<< 16]
Definition: acwing.h:433

引用了 compress(), decompress(), fsm , 以及 n.

被这些函数引用 main().

◆ main()

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

在文件 acwing.cpp1115 行定义.

1115 {
1116 memset(fsm, -2, sizeof fsm);
1117 unsigned long long b;
1118 cin >> n >> b;
1119 unsigned int status = 0;
1120 for(int i = 0; i < n; i++) {
1121 unsigned int bulb;
1122 cin >> bulb;
1123 status += bulb;
1124 status <<= 1;
1125 }
1126 status >>= 1;
1127 fsm[status] = -1;
1128
1129 int count = 0;
1130 int round = 0;
1131 unsigned int index = 0;
1132 for(int i = 0; i < b; i++) {
1133 if(fsm[status] >= 0) {
1134 if(round == 0) {
1135 round = 1;
1136 index = status;
1137 } else if(round == 1 && status == index) {
1138 b = (b - i) % count + i;
1139 round = 2;
1140 }
1141 }
1142 if(round == 1) {
1143 count++;
1144 }
1145 status = get_next(status);
1146 }
1147 const auto *const ans = decompress(status);
1148 for(int i = 0; i < n; i++) {
1149 cout << static_cast<int>(ans[i]) << endl;
1150 }
1151 delete[] ans;
1152 return 0;
1153 }
unsigned int get_next(unsigned int status)
Definition: acwing.cpp:1155

引用了 decompress(), fsm, get_next() , 以及 n.

类成员变量说明

◆ fsm

int acwing::acwing1960::fsm[1<< 16] = {}
private

在文件 acwing.h433 行定义.

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

◆ n

unsigned int acwing::acwing1960::n {}
private

在文件 acwing.h434 行定义.

被这些函数引用 compress(), decompress(), get_next() , 以及 main().


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