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. 使用Python在自己博客上进行自动翻页

    先上一张代码及代码运行后的输出结果的图! 下面上代码: # coding=utf-8 import os import time from selenium import webdriver #打开火 ...

  2. pssh批量管理

    因为公司金融项目正式上线,有等保的要求,所有的线上服务器对操作过历史命令都要记录下来,需要修改一部分的配制文件.总共有300多台Linux服务器,总不能一台一台去改吧.首先想到是ansble,salt ...

  3. 关于mysql触发器和存储过程的理解

    内容源自:一篇很棒的 MySQL 触发器学习教程 一.触发器概念 触发器(trigger):监视某种情况,并触发某种操作,它是提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊 ...

  4. BIOS备忘录之ASL code常用知识点

    _HID:device唯一 _STA:决定device在不在(在DM下面能不能看到) _CRS:描述分配给device的资源 _INI:在OSPM加载描述表的时候运行一次(比如,如果要根据不同情况给d ...

  5. jQuery安装和语法

    jQuery是一个JavaScript函数库,可实现HTML元素选取及操作.CSS 操作.HTML事件函数.JavaScript特效和动画.HTML DOM遍历和修改.AJAX等功能. 在html中引 ...

  6. 常见的python的unittest用法

    python的unittest好处是通过python脚本编写用例,每个用例可以单独调试初始化和清理动作,因为都是用例都是代码所以调试起来也很方便:它的缺点是得先学会python,难易程度见仁见智吧,对 ...

  7. JavaScript Dom 事件

    JavaScript  Dom 事件 对于事件需要注意的要点: // this标签当前正在操作的标签. this // event封装了当前事件的内容. even 常用事件 // 鼠标单击.触发事件 ...

  8. Python sqlalchemy orm 多外键关联

     多外键关联 注:在两个表之间进行多外键链接 如图: 案例: # 创建两张表并添加外键主键 # 调用Column创建字段 加类型 from sqlalchemy import Integer, For ...

  9. 随机森林和GBDT

    1. 随机森林 Random Forest(随机森林)是Bagging的扩展变体,它在以决策树 为基学习器构建Bagging集成的基础上,进一步在决策树的训练过程中引入了随机特征选择,因此可以概括RF ...

  10. 7.6 GRASP原则六: 多态 Polymorphism

    GRASP原则六: 多态 Polymorphism  How to handle alternative behaviors based on type 如何处理依据类型不同而有 不同行为的一类需求 ...