求hack
查看原帖
求hack
733577
Naus楼主2023/8/30 06:53
#include<bits/stdc++.h>
using namespace std;
int t,n,p,cnt;
queue<int>q[200001];
int main(){
    cin>>t;
    while(t--){
        cnt=0;
        cin>>n>>p;
        if(p>=2*n||p==1){
            for(int i=1;i<=n;i++) cout<<i<<" ";
            cout<<endl;
            continue;
        }
        for(int i=1;i<=n;i++) q[i%p].push(i);
        while(q[0].size()) cout<<q[0].front()<<" ",q[0].pop(),cnt++;
        if(cnt==n){
            cout<<endl;
            continue;
        }
        for(int i=1;cnt<n;i++){
            if(q[p-i].empty()) while(q[i].size()) cout<<q[i].front()<<" ",q[i].pop(),cnt++;
            else if(q[i].empty()) while(q[p-i].size()) cout<<q[p-i].front()<<" ",q[p-i].pop(),cnt++;
            else if(i==p-i) while(q[i].size()) cout<<q[i].front()<<" ",q[i].pop(),cnt++;
            else if(q[i].size()>q[p-i].size()) while(q[p-i].size()) cout<<q[p-i].front()<<" "<<q[i].front()<<" ",q[p-i].pop(),q[i].pop(),cnt+=2;
            else while(q[i].size()) cout<<q[i].front()<<" "<<q[p-i].front()<<" ",q[i].pop(),q[p-i].pop(),cnt+=2;
        }
        cout<<endl;
    }
}

rt,感觉是边界写错之类的,但是没看出来。

lz还要上学,可能得晚上再来看。

2023/8/30 06:53
加载中...