Parliament

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18707   Accepted: 7941

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

 
分析:
题目的意思是,将一个数字拆分成互不相同的数,使它们的积最大。
 
解题:
如果不考虑条件“互不相同的”,那么最终结果肯定是2\3的组合(4拆2+2效果一样),比如10=5+5=2+3+2+3。
将“互不相同”纳入考虑范围,那么,这个组合必然是从2开始的,尽可能小的,一组数列。
那么可以,从2+3+4+...加到一个不大于N的值,再将剩余的值从大到小加回去。比如,26=2+3+4+5+6....6,再将6从大到小依次加回去,就得到答案3+4+5+6+8
 
 #include <stdio.h>

 int main(void)
{
int ans[] = {};
int all = ;
int sum = ;
int end = ;
int num = ;
int j = ;
int remaind = ;
scanf("%d",&all); while()
{
if(sum+end <= all)
{
sum = sum+end;
ans[num] = end;
num++;
end++;
}
else
{
remaind = all - sum;
break;
}
} j = num - ;
while(remaind > )
{
if(j<) j=num-;
ans[j]++;
j--;
remaind--;
} for(j=; j<num; j++)
{
printf("%d ", ans[j]);
} return ;
}

北大poj- 1032的更多相关文章

  1. 北大POJ题库使用指南

    原文地址:北大POJ题库使用指南 北大ACM题分类主流算法: 1.搜索 //回溯 2.DP(动态规划)//记忆化搜索 3.贪心 4.图论 //最短路径.最小生成树.网络流 5.数论 //组合数学(排列 ...

  2. poj 1032 Parliament 【思维题】

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

  3. POJ 1032问题描述

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

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

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

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

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

  6. 【贪心】 poj 1032 和为n的若干数最大乘积

    给出n,把n分解为若干不相同数之和,使之乘积最大.贪心,Discuss里面的思路:把n分解为从2开始的连续整数,如果有多,则从高位开始依次加1.如26,我们得到2+3+4+5+6,此时还剩余6(26- ...

  7. Poj 1032 Parliament

    Parliament Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19103   Accepted: 8101 Descr ...

  8. POJ 1032

    #include<iostream> using namespace std; int main() { int n; int num; ; int i,j; cin>>num ...

  9. 【Java】深深跪了,OJ题目Java与C运行效率对比(附带清华北大OJ内存计算的对比)

    看了园友的评论之后,我也好奇清橙OJ是怎么计算内存占用的.重新测试的情况附在原文后边. -------------------------------------- 这是切割线 ----------- ...

  10. POJ 1861 Network (Kruskal算法+输出的最小生成树里最长的边==最后加入生成树的边权 *【模板】)

    Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14021   Accepted: 5484   Specia ...

随机推荐

  1. Ajax跨域请求COOKIE无法带上的解决办法

    原生ajax请求方式: var xhr = new XMLHttpRequest(); xhr.open("POST", "http://xxxx.com/demo/b/ ...

  2. Json的转换

    package com.utils; import java.io.IOException; import java.util.List; import org.codehaus.jackson.Js ...

  3. Shell 变量知识

    1.自定义变量:自定义变量不能以数字开头. ()root#a=’cd /etc/’ #设置自定义变量. root#etho $a #使用变量. 2.全局变量:export可设置全局变量不能以数字开头. ...

  4. 剑指offer(10)矩形覆盖

    题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 题目分析 当然也可以逆向思维 应为可以横着放或竖着放,多以f ...

  5. 动态从数据库获取数据,省市县三级联动,有校验,导出Excel模板

    话不多说,看效果图,直接上代码. sheet  商户表 hideSheet ,功能完成后隐藏的Sheet,用于储存下拉框中的信息,(以一定的规则将所需数据存储在表格中). 下面是代码 部分数据需要在导 ...

  6. visual studio中csproj文件中的project guid改为小写

    安装了vs2019之后,发现有的项目中引用的其他项目的源码,但是无法识别了. 最后发现是因为project guid是大写导致的. https://stackoverflow.com/question ...

  7. 通过Python计算一个文件夹大小

    在进行计算一个文件夹内容大小的时候,我们要考虑文件夹内都有什么内容,可能都是一个一个的单文件,也有可能都是子文件夹,或者二者都有,既然要计算整个文件夹的大小,我们当然要计算每一个文件的大小以及每一个子 ...

  8. Leetcode480-Binary Tree Paths-Easy

    480. Binary Tree Paths Given a binary tree, return all root-to-leaf paths. Example Example 1: Input: ...

  9. 全局解释器锁GIL & 线程锁

    1.GIL锁(Global Interpreter Lock) Python代码的执行由Python虚拟机(也叫解释器主循环)来控制.Python在设计之初就考虑到要在主循环中,同时只有一个线程在执行 ...

  10. CSS基础学习(一) 之 line-height 与 height 属性区别

    官方定义: height:定义了了元素的高度.默认情况下,该属性订了 content area(内容区域) 的高度.如果box-sizing属性设置为 border-box,那么height就表示bo ...