80分BFS求助
查看原帖
80分BFS求助
285414
Swiftie_wyc22楼主2021/3/6 14:28
#include <iostream>
#include <queue>
#include <cstdio>

using namespace std;
#define ULL unsigned long long
ULL n;
unsigned long long ans2;

ULL BFS() {
    queue<ULL> q;
    ULL ans, tail;
    ULL xx;
    q.push(1);
    while (!q.empty()) {
        tail = q.front();
        q.pop();
        for (int i = 0; i < 2; i++) {
            xx = tail * 10 + i;
            if (xx % n == 0) {
                ans2 = xx/n;
                return xx;
            } else {
                q.push(xx);
            }
        }
    }
}

int main() {
        cin >> n;
        ULL ans;
        ans = BFS();
        cout << ans2 << " " << ans << endl;
    return 0;
}

这道题的ans2可以看出是临时加上的,是在做完Find The Multiple之后过来做的,只拿了80分,我也不知道是哪里错了

2021/3/6 14:28
加载中...