您的位置:首页 > 其它

poj 1032

2017-01-22 11:05 183 查看

题目

Parliament

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 18695 Accepted: 7934
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 Code
Problem: 1032 User: PaladinDu
Memory: 164K Time: 16MS
Language: C Result: Accepted
Source Code
#include <stdio.h>
/*
* 求乘集最大的整数集合,数字不能重复,且和等于N。
* 很显然,数字数量越多越好,不要有1。数字相同的情况下靠的越紧越大
* 可以预期这个整数集
* 是一段连续的数,或是两段连续的数且中间只间隔一个数
* 这个里的N范围很小,可以打表,不过没什么意义。
*/
#define __INT_BUF_LEN__ 100
int TMP[__INT_BUF_LEN__];//存从2开始,到n的和
void fInit()
{
int i ;
TMP[1]=0;
for(i=2;i<__INT_BUF_LEN__;++i)
{
TMP[i]=TMP[i-1]+i;
}
}

int main() {
int N;
int i,j,dif;
fInit();
scanf("%d",&N);

for(i=3;i<__INT_BUF_LEN__;++i)
{
if(TMP[i]>N)
{
break;
}
}

dif = TMP[i]-N;
/*
* 有两种中情况
* 如果dif=1 #因为我们总是不用1所以没法用1来填补差值
* 就是3到i-1加上i+1
* 如果是其他则是
* 2到dif-1加上dif+1到i (dif == 2 || def ==i )是去头去尾
*/
switch(dif)
{
case 1:
for(j=3;j<=i-1;++j)
{
printf("%d ",j);
}
printf("%d",i+1);
break;
default:
for(j=2;j<=i;++j)
{
if(j!=dif)
{
printf("%d ",j);
}
}
break;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  poj