编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#12490 #55. 「2021 新生杯」Collatz 猜想 Accepted 100 19 ms 632 K C++ 17 / 1017 B susanzhishen 2023-12-07 23:39:51
显示原始代码
#include <bits/stdc++.h>
#define int long long

#define x first

#define y second

using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 5e6 + 10;
const int M = 2e3 + 10;
int mod = 1e9 + 7;
map<int, int> mp, vis;
int k;
struct Link {
    int x, w;
};
void bfs(int sx) {
    queue<Link> que;
    que.push({ sx, 0 });
    while (!que.empty()) {
        Link p = que.front();
        que.pop();
        if (vis[p.x])
            continue;
        vis[p.x] = 1;
        mp[p.x] = p.w;
        if (p.w == k)
            continue;
        if (p.x % 2 == 1) {
            if (vis[p.x * 2] == 0)
                que.push({ p.x * 2, p.w + 1 });
        } else {
            if (vis[p.x * 2] == 0)
                que.push({ p.x * 2, p.w + 1 });
            if ((p.x - 1) % 3 == 0 && vis[(p.x - 1) / 3] == 0)
                que.push({ (p.x - 1) / 3, p.w + 1 });
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n >> k;
    bfs(1);
    int ans = 0;
    for (auto it : mp) {
        if (it.x <= n)
            ans++;
    }
    cout << n - ans;
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:3 ms
内存:292 KiB

输入文件(1.in

5 2

答案文件(1.ans

2

用户输出

2

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:4 ms
内存:336 KiB

输入文件(2.in

10 3

答案文件(2.ans

6

用户输出

6

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:3 ms
内存:288 KiB

输入文件(3.in

1000 10

答案文件(3.ans

972

用户输出

972

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:3 ms
内存:384 KiB

输入文件(4.in

1000000 20

答案文件(4.ans

999659

用户输出

999659

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:6 ms
内存:632 KiB

输入文件(5.in

1000000000 30

答案文件(5.ans

999996483

用户输出

999996483

系统信息

Exited with return code 0