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

  

POJ-1032-拆数字的更多相关文章

  1. (Relax 水题1.2)POJ 1032 Parliament(将n分解成若干个互不相等的整数的和,并且是这些整数的乘积最大)

    题意:给出一个数n,将其拆分为若干个互不相等的数字的和,要求这些数字的乘积最大. 分析:我们可以发现任何一个数字,只要能拆分成两个大于1的数字之和,那么这两个数字的乘积一定大于等于原数.也就是说,对于 ...

  2. poj 2516(拆点+最小权匹配)

    题目链接:http://poj.org/problem?id=2516 思路:考虑某种货物,由于某个订货商可能接受来自不同地区的货物,而某一地区的货物也可能送给不同的订货商,显然不能直接进行匹配,必须 ...

  3. poj 3686(拆点+最小权匹配)

    题目链接:http://poj.org/problem?id=3686 思路:显然工件为X集,机器为Y集合.由于每个机器一次只能加工一个部件,因此我们可以将一台机器拆成N个点,至于部件与机器之间连多大 ...

  4. poj 1698(拆点+最大匹配)

    题目链接:http://poj.org/problem?id=1698 思路:最大匹配容易想到,关键是如何建图,这里我们可以将电影按需要的天数进行拆点,然后对于可以选择的日子连边,最后只需判断最大匹配 ...

  5. poj 1032 Parliament 【思维题】

    题目地址:http://poj.org/problem?id=1032 Parliament Time Limit: 1000MS   Memory Limit: 10000K Total Submi ...

  6. POJ 3686 & 拆点&KM

    题意: 有n个订单,m个工厂,第i个订单在第j个工厂生产的时间为t[i][j],一个工厂可以生产多个订单,但一次只能生产一个订单,也就是说如果先生产a订单,那么b订单要等到a生产完以后再生产,问n个订 ...

  7. Poj 1032 分类: Translation Mode 2014-04-04 09:09 111人阅读 评论(0) 收藏

    Parliament Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16521   Accepted: 6975 Descr ...

  8. poj 2229 拆数问题 dp算法

    题意:一个n可以拆成 2的幂的和有多少种 思路:先看实例 1   1 2    1+1     2 3     1+1+1  1+2 4      1+1+1+1  1+1+2  2+2  4 5  ...

  9. POJ 1111(数字很吉利嘛) 简单BFS

    Image Perimeters Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8594 Accepted: 5145 Desc ...

  10. POJ 1032问题描述

    Description New convocation of The Fool Land's Parliament consists of N delegates. According to the ...

随机推荐

  1. 用GA算法设计22个地点之间最短旅程-R语言实现

    数据挖掘入门与实战  公众号: datadw 相关帖子 转载︱案例 基于贪心算法的特征选择 用GA算法设计22个地点之间最短旅程-R语言实现 ----------------------------- ...

  2. Android 4.4以上使用HttpURLConnection底层使用OkHttp实现的源码分析

    研究了一下HttpURLConnection的源码: 在使用的时候都是通过URL.openConnection()来获取HttpURLConnection对象,然后调用其connect方法进行链接,所 ...

  3. freemarker报错之十一

    1.错误描述 六月 03, 2014 11:00:35 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  4. freemarker嵌入文件输出结果

    freemarker嵌入文件输出结果 1.嵌入的文件代码 inc.ftl: <#assign username="李思思"> 2.父文件代码 inner.ftl: &l ...

  5. tomcat原理(二)

    一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命令的用法如下:

  6. 求字符串空格、数字、字母个数--JAVA基础

    相关内容:charAt()函数 package com.nxl123.www;public class NumString { public static void main(String[] arg ...

  7. P2500 - 【DP合集】背包 bound

    题面 Description N 种物品,第 i 种物品有 s i 个,单个重量为 w i ,单个价值为 v i .现有一个限重为 W 的背包,求能容 纳的物品的最大总价值. Input 输入第一行二 ...

  8. 一道java基础面试题

    package test; class A {    public A(){        System.out.println("A3");    }    {        S ...

  9. webapi下的web请求

    先看webapi提供的服务: [HttpPost] public ResultBaseModel SiteList(SiteModel param) { ResultBaseModel resultM ...

  10. 用js实现左右阴影的切换

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...