POJ 1032 Parliament

Parliament
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 14977 Accepted: 6332

Description

New convocation of The Fool Land's Parliament consists of N delegates. According to the present regulation delegates should be divided into disjoint groups of different sizes and every day each group has to send one delegate to the conciliatory committee. The composition of the conciliatory committee should be different each day. The Parliament works only while this can be accomplished.
You are to write a program that will determine how many delegates should contain each group in order for Parliament to work as long as possible.

Input

The input file contains a single integer N (5<=N<=1000 ).

Output

Write to the output file the sizes of groups that allow the Parliament to work for the maximal possible time. These sizes should be printed on a single line in ascending order and should be separated by spaces.

Sample Input

7

Sample Output

3 4

Source

这题首先纠结在题意上面,后来发现所谓使议会工作时间尽可能长的意思就是让分成的组的议员的组合形式尽可能多。
于是题目转变成如下的数学模型:
对于任意的正整数N,将其分解为a1,a2,...,an.令所有元素各不相同;求一种分法使a1*a2*...an的积最大。
说实话,数论神马的最无爱了,因为没学过的话怎么想也没用,只能上网去查,于是得到大牛的结论和证明过程,简单总结如下:
首先得到一组递增数列a1,a2,...,an;
1.1不能成为数列中一个,显然1,2,...,a[n-1]-1,a[n]之积没有2,3,...,a[n-1]-1,a[n]+1大;
2.任意两项之差小于等于2,因为若是有a[n],a[n]+3,就可以转化为a[n]+1,a[n]+2,就是乘积更大;
3.首项只能是2或3,因为若首项是4的话,其后必为5或6,而5可以转化为2,3;6则可转化为2,4;
4.a[i],a[i]+2的连续两项只能存在1次;因为若有a[j],a[j]+2(i<j)这样的两项可以转化为a[i]+1,a[i+2],a[j],a[j+1],这样乘积更大;
5.若有a1=3且a[i],a[i]+2的连续两项,i=n-1;若i<n-1,将a[n]转化为2,a[n]-2两项可使乘积更大;
具体做法如下:
设A={2,3,...,i}使sum=2+3+4+...+i<=N,令m=N-sum;
若m=i,则把数列中前i-2项加1,最后一项加2;
若m<i,则把数列中从大到小的每一项加1,直到m归零。
#include<iostream>
using namespace std;
int main()
{int r[50];
int i,j,m,n,sum;
while(cin>>n)
{memset(r,0,sizeof(r));
sum=0;
i=2;j=0;
while(sum+i<=n)
	{sum+=i;
     r[j]=i;
	 i++;j++;}
m=n-sum;
if(m==i-1)
{
	for(j=0;j<i-2;j++)
		r[j]++;
	r[j-1]++;
}
else
{
	for(j=i-3;j>=0,m!=0;j--)
	{r[j]++;m--;}
}
for(i=0;r[i]!=0;i++)
	cout<<r[i]<<" ";
    cout<<endl;
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值