比赛 2026初中综合小练习 评测结果 AAAAA
题目名称 求集合中最小的N个数 最终得分 100
用户昵称 张宸汉 运行时间 0.928 s
代码语言 C++ 内存使用 22.03 MiB
提交时间 2026-04-14 21:05:55
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
struct compare{
    bool operator()(int a,int b){
        return a>b;
    }
};
int main()
{
    freopen("minvalinset.in","r",stdin);
    freopen("minvalinset.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,x=1,y=1,z=1;
    cin>>n;
    priority_queue<long long, vector<long long>,compare> q;
    unordered_set<long long> vis;
    q.push(1);
    vis.insert(1);
    for (int i = 0; i < n; i++) {
        long long now = q.top();
        q.pop();
        cout << now << " ";
        long long y = 2 * now + 1;
        long long z = 3 * now + 1;
        if (!vis.count(y)) {
            vis.insert(y);
            q.push(y);
        }
        if (!vis.count(z)) {
            vis.insert(z);
            q.push(z);
        }
    }

    return 0;
 }