CF1017C The Phone Number

Dilworth定理了解一下?

同机房大佬发现,大概是将1~n每(sqrt(n)+1/(sqrt(n))分一段,但是后面那个1/sqrt(n)太小,可以忽略,然后就每sqrt(n)分一段,结果就过了

代码

//By AcerMo
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
signed main()
{
	int n,e,m=0;
	cin>>n;e=ceil(sqrt(n));
	for (int i=1;i<=e;i++)
	for (int k=1;k<=e;m++,k++)
	if (n-i*e+k>0) cout<<n-i*e+k<<" ";
	for (int i=1;i<=n-m;i++) 
	cout<<i<<" ";
	return 0;
}

猜你喜欢

转载自blog.csdn.net/ACerAndAKer/article/details/81737857