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

AcWing 4300. 两种操作 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 

详细描述

AcWing 4300. 两种操作

在文件 acwing.h1187 行定义.

成员函数说明

◆ main()

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

在文件 acwing.cpp3815 行定义.

3815 {
3816 int n;
3817 int m;
3818 cin >> n >> m;
3819 auto um = unordered_set<int>();
3820 auto que = queue<pair<int, int>>();
3821 que.push(make_pair(n, 0));
3822 um.insert(n);
3823 while(!que.empty()) {
3824 auto [current, step] = que.front();
3825 que.pop();
3826 if(current == m) {
3827 cout << step;
3828 return 0;
3829 }
3830 int k = 1;
3831 const int nexts[2] = {current - 1, current * 2};
3832 if(current < m) {
3833 k = 2;
3834 }
3835 for(int i = 0; i < k; i++) {
3836 auto next = nexts[i];
3837 if(next == m) {
3838 cout << step + 1;
3839 return 0;
3840 }
3841 if(next > 0 && !um.contains(next)) {
3842 que.push(make_pair(next, step + 1));
3843 um.insert(next);
3844 }
3845 }
3846 }
3847 return 0;
3848 }

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


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