球 hack
查看原帖
球 hack
820839
zly2009楼主2023/8/20 21:49

赛时有点脑抽,貌似 40 分但是错的点和大部分人都不一样(?)

#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
	int t;
	cin>>t;
	while(t--){
		map<int,bool>mp;
		int n,p;
		cin>>n>>p;
		if(p==2){
			for(int i=1;i<=n;i+=2)cout<<i<<' ';
			for(int i=2;i<=n;i+=2)cout<<i<<' ';
		}
		else {
			for(int i=1;i<=n;i++){
				if(mp[i])continue;
				int s=p,t=i;
				while(t<=n&&t>0&&!mp[t]){
					cout<<t<<' ';
					mp[t]=1;
					t=s-t;
					s+=p;
				}
			}
		}
		puts("");
	}
}

思路就是 nn 个数跑,然后能凑成 pp 的倍数的输出,之后遇到就不算了。

2023/8/20 21:49
加载中...