首页 技术 正文
技术 2022年11月13日
0 收藏 754 点赞 3,940 浏览 1198 个字

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
题目大意:
将整数n,(5<=n<=1000)拆成多个不相等的数(和),使所以有的数之积最大。
思路;
一个数n入能被2 整除,则(n/2)*(n/2)最大;若不能则(n/2)*(n/2+1)最大
所以启发:把一个数从小的开始分,把剩余的部分分别加到后面大数上
所有数开始拆:
例如 7:先拆成:2 3 剩余2 ,分别让2,3加1,得3 4;
例如 8:拆成2 3 剩余3;分别让2 3 加1 ,还余1;让3加1再加1;得3 5;
例如 9 :直接拆成2 3 4;
#include<iostream>
using namespace std;
int main()
{ int n,s=0,a[100]={0};
cin>>n;
int i;
for(i=2;s+i<=n;i++)//注意不能仅仅让s<=n;这样会导致多循环一次
{
a[i]=i;
s+=i;
} int h=i;
for(int j=n-s;j>0;j--)//把剩余的即n-s部分从数组最后往前均分
{
a[--i]++;
if(i==2)i=h;//第一遍均分后让i回到最后再开始均分 }
for(int k=2;k<h;k++)
{
cout<<a[k]<<" ";
}
return 0;
}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,954
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,479
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,291
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,108
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,740
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,774