//Eric M.Schmidt编写的C++代码,用于计算OEIS中的序列A097981。//根据CC0,我特此放弃对本规范的所有权利//弃权:// http://creativecommons.org/publicdomain/zero/1.0/#包括#包括#包括typedef标准::对Pnt;typedef标准::矢量CellList;Pnt运算符+(Pnt pnt1,Pnt pnt2){返回{pnt1.first+pnt2.first,pnt1.second+pnt1.second};}std::数组常量邻偏移{{{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}};CellList应用的种子(CellList-const和cells){单元格列出新单元格;newcells.reserve(cells.size());标准::映射>邻居信息;for(Pnt常量&Pnt:单元格){邻居信息[pnt].second=true;for(Pnt常量偏移量:相邻偏移量){++邻居信息[pnt+offset].first;}}for(自动常量单元格:邻居信息(&C){Pnt常数&Pnt(单元格优先);int const&numNeighbors(cell.second.first);bool常量&wasAlive(cell.second.second);if(!wasAlive&&numNeighbors==2){newcells.push_back(pnt);}}返回新单元格;}//主计算b文件到n=1000#包括整型main(){CellList模式{{0,0},{0,1},};对于(int ii(0));ii<=1000++ii){标准::cout<<ii<<''<<pattern.size()<<std::endl;pattern=应用种子(pattern);}}