poj 1032

假设最大积的分解为

n=a1+a2+a3+...+a[t-2]+a[t-1]+a[t]

(a1<a2<a3<...<a[t-2]<a[t-1]<a[t])

我们来证明这个数列的一些性质;

1.1<a1

if a1=1, then a1(=1), a[t] together could be replaced by a[t]+1.

2.to all i, a[i+1]-a[i]<=2;

if some i make a[i+1]-a[i]>=3,

then a[i],a[i+1] together could be replaced by a[i]+1,a[i+1]-1 together.

3. at MOST one i, fits a[i+1]-a[i]=2

if i<j and a[i+1]-a[i]=2 and a[j+1]-a[j]=2 then

a[i],a[j+1] could be replaced by a[i]+1, a[j+1]-1



4. a1<=3

if a1>=4, then a1,a2 together could be replaced by 2, a1-1, a2-1 together

5. if a1=3 and one i fits a[i+1]-a[i]=2 then i must be t-1

if i<t-1 then a[i+2] could be replaced by 2, a[i+2]-2 together

Now, from the five rules above, we could make the mutiple maximum.

to an N, find the integer k, fits

A=2+3+4+...+(k-1)+k <= N < A+(k+1)=B

Suppose N = A + p, (0 <= p < k+1)

1) p=0, then answer is Set A

2) 1<=p<=k-1 then answer is Set B - { k+1-p }

3) p=k, then answer is Set A - {2} + {k+2}

We can prove this is the best choice with ease,

as any other choice will lead to at least one of the following:

1) a1>=4 or a1=1

2) two a[i+1]-a[i]=1 or one a[i+1]-a[i]=2

3) a1=3 and some i<t-2 fits a[i+1]-a[i]=1
代码:
#include<iostream>
#include<fstream>
#include<cmath>

using namespace std;
void read(){
//	ifstream cin("in.txt");
	int i,j,k;
	cin>>k;
	k++;
	i=sqrt(2.*k);
	if((1+i)*i>2*k) i--;
	k--;
	if((2+i)*(i-1)==2*k)
	{
		for(j=2;j<=i;j++)
			cout<<j<<' ';
		cout<<endl;
	}
	else
		if((2+i)*(i-1)/2+i==k)
		{
			for(j=3;j<=i;j++)
				cout<<j<<' ';
			cout<<i+2<<endl;
		}
		else
		{
			int p=k-(2+i)*(i-1)/2;
			for(j=2;j<=i+1;j++)
				if(j!=i+1-p)
					cout<<j<<' ';
			cout<<endl;
		}
}


int main(){
	read();
	return 0;
}


转载于:https://www.cnblogs.com/zhaozhe/archive/2011/04/19/2020918.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值