help!最后一点T,零零散散的WA
查看原帖
help!最后一点T,零零散散的WA
797897
_QyGyQ_楼主2023/8/21 08:37
#include<bits/stdc++.h>
#define int long long
using namespace std;
using ll=long long;
const int N=1e5+7;
int a[N];
int b[N];
int f;
signed main(){
	int n,p,t,cnt=0;
	cin>>t;
	while(t--){
		cin>>n>>p;
		f=0,cnt=0;
		memset(b,0,sizeof b);
		memset(a,0,sizeof a);
		if(p==2){
			for(int i=1;i<=n;i++){
				if(i%2==1) cout<<i<<" ";
			}
			for(int i=1;i<=n;i++){
				if(i%2==0) cout<<i<<" ";
			}
			puts("");
		}
		else{
			for(int i=1;i<=n;i++){
				a[i]=i;
				if(i%p==0){
					b[i]=-1;
					cout<<i<<" ";
					f++;
				}
				else{
					b[i]=i%p;
				}
			}
			if(f==n) puts("");
			else{
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						if(b[i]!=-1&&b[j]!=-1){
							if(b[i]+b[j]==p){
								cout<<a[i]<<" "<<a[j]<<" ";
								b[i]=-1,b[j]=-1;
							}
						}
						if(b[i]==-1&&b[j]==-1) break;
					}
				}
				for(int i=1;i<=n;i++){
					if(b[i]!=-1){
						cout<<a[i]<<" ";
					}
				}
				puts("");
			}
		}
	}
	return 0;
}

2023/8/21 08:37
加载中...