题解 | 冰冻青蛙

冰冻青蛙

https://www.nowcoder.com/practice/2f0095ac4680450e934f171bff254f38

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using PII=pair<ll,ll>;
using PIII=pair<int,pair<int,int>>;
const ld ESP = 1e-10;
const ld PI = acosl(-1);
const int N=1e5+10;
const int M=2e5+10;
// const int mod = 1000000007;
const int mod = 998244353;
//随机化
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(1, 1000000000);
// cout<<fixed<<setprecision(10);


void solve(){
    // int x=999999999;
    // vector<pair<int,int>> ans;
    // for(int i=2;i*i<=x;i++){
    //     int cnt=0;
    //     while(x%i==0){
    //         cnt++;
    //         x/=i;
    //     }
    //     if(cnt){
    //         ans.push_back({i,cnt});
    //     }
    // }  
    // if(x)ans.push_back({x,1});
    // for(auto [p,cnt]:ans){
    //     cout<<p<<" "<<cnt<<'\n';
    // }
    // 3 4
    // 37 1
    // 333667 1
    int n;
    cin>>n;
    int cnt=n/3+n/37;
    if(n<=cnt*3){
        vector<int> v(n+1,0);
        vector<int> ans(n+1,-1);
        vector<int> pos;
        for(int i=2;i<=n;i+=3){
            pos.push_back(i);
        }
        if(n%3==1){
            pos.push_back(n);
        }
        int y=3,z=37;
        for(auto x:pos){
            if(y<=n){
                ans[x]=y;
                v[y]=1;
                y+=3;
            }else if(z<=n){
                ans[x]=z;
                v[z]=1;
                z+=37;
            }
        }
        int p=1;
        for(int i=1;i<=n;i++){
            if(ans[i]==-1){
                while(v[p]){
                    p++;
                }
                ans[i]=p;
                v[p]=1;
            }
        }
        for(int i=1;i<=n;i++){
            cout<<ans[i]<<" ";
        }
    }else{
        cout<<"Baka!"<<'\n';
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _=1;
    // cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

全部评论

相关推荐

程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务