6分求调
查看原帖
6分求调
1724170
zhapenghui楼主2025/7/21 10:03
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=1e5;
int b[M];
bool check(int list[],int k)
{
	int list2[k+2];
	for (int i=1;i<=k;i++)
		list2[i]=list[i];
	sort(list2+1,list2+k+1);
	for (int i=2;i<=k;i++)
		if (list2[i]==list2[i-1])
			return false;
	return true;
	/*for (int i=1;i<k;i++)
		if (list[i]==m)
			return false;
	return true;*/
}
signed main()
{
	int a;
	cin>>a;
	
	b[1]=1;
	for (int i=2;i<=a;i++)
	{
		b[i]=b[i-1]-i;
		
		if (b[i]>0&&check(b,i))
		{
			
			b[i]=b[i-1]-i;
		}
		else
		{
			
			b[i]=b[i-1]+i;
		}
	}
	sort(b+1,b+a+1);
	for (int i=1;i<=a;i++)
		cout<<b[i]<<" "; 
}
2025/7/21 10:03
加载中...