pku(1032)Parliament

作者在 2008-03-31 13:47:01 发布以下内容
贴道值得研究的题吧,虽然有人给出了解法,也总结出很多规律,可还是没有看到很好的证明
 
大意是把整数N分成不相等的任意个整数,使这些数乘积最大
 
有人总结了一些规律:
1.1<a1

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

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

if some i make a[i+1]-a[i]>2,
then a[i],a[i+1] together could be replaced by a[i]+1,a[i+1]-1 together.

reason: a[i]*a[i+1] < (a[i]+1)*(a[i+1]-1)
(a[i]+1)*(a[i+1]-1)=a[i]*a[i+1]+a[i+1]-a[i]-1
so a[i+1]-a[i]-1>0   (* a[i+1]-a[i]>2)

----------------------------------------------------------------------------------------
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

reason: a[i]*a[j+1]< (a[i]+1)*(a[j+1]-1)
so a[j+1]-a[i]-1>0   (* a[j]-a[i]>=1 a[j+1]-a[j]>=1 so a[j+1]-a[i]>=2 )

----------------------------------------------------------------------------------------
4. a1<=3

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

reason: a1*a2< 2*(a1-1)(a2-1)
(a1-1)(a2-1)=a1*a2-a1-a2+1
so a1*a2>2*(a1+a2-1) (* a1>=4 and a2>=5)

----------------------------------------------------------------------------------------
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
reason: a[i+2]<2*(a[i+2])-4
so a[i+2]>4  (* a[1]=3 a[3]>=5 so a[i+2]>=5)
 
做法就是求出以2起始的最大连续自然数序列之和sum,使得sum的值不超过输入数n,
然后分情况讨论:

设此最大序列为2、3、……、w,则:

1。若剩余值(n-sum)等于w,则最后输出序列为:3、4、……、w、w+2,即将原最大序列每项加1,再将最后剩余的一个1加到最后一项上。

2。若剩余值(n-sum)小于w,则从序列的最大项i开始,从大到小依次将每项加1,直到剩余值用完。
acm | 阅读 3723 次
文章评论,共0条
游客请输入验证码
浏览255960次