题目地址:http://poj.org/problem?id=1032

Parliament
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17473   Accepted: 7371

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从2开始进行分解,注意:每个被分解出来的数都必须是不同的。比如:6= 3+3; 3,3是不合法的!
(1).若 n = 2 + 3 + ... + k + k ,不够减的数余下为k, 则将其转换成:n=3+4+..+k+(k+2);
比如:13=2+3+4+4,则转换成:13=3+4+6
(2).若不够减的数余下小于k,则将余下的n,从最大的数开始往前分配1。
比如: 10=2+3+4+1; 则转换成:10=2+3+5;
代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <queue>
#include <iostream>
#include <string>
#include <algorithm> using namespace std; int main()
{
int n;
int i, j;
int a[1010];
int e=0; scanf("%d", &n); for(i=2; i<=n; i++)
{
a[e++]=i;
n=n-i;
}
if(n<a[e-1] && n>0 )
{
for(i=e-1; i>=0; i--)
{
a[i]++;
n--;
if(n==0) break;
}
}
else if(n==a[e-1])
{
for(i=0; i<e; i++) a[i]++;
a[e-1]++;
}
for(i=0; i<e; i++)
{
if(i==0) printf("%d", a[i]);
else printf(" %d", a[i]);
}
printf("\n");
return 0;
}
												

poj 1032 Parliament 【思维题】的更多相关文章

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

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

  2. Poj 1032 Parliament

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

  3. UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)

    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...

  4. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  5. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  6. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  7. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  8. 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)

    思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...

  9. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. PHP面试题及答案解析(6)—PHP网络编程

    1.禁用COOKIE后SEESION还能用吗? 可以,COOKIE和SESSION都是用来实现会话机制的,由于http协议是无状态的,所以要想跟踪一个用户在同一个网站之间不同页面的状态,需要有这么一个 ...

  2. flume配置和说明(转)

    Flume是什么 收集.聚合事件流数据的分布式框架 通常用于log数据 采用ad-hoc方案,明显优点如下: 可靠的.可伸缩.可管理.可定制.高性能 声明式配置,可以动态更新配置 提供上下文路由功能 ...

  3. SpringBoot集成actuator模块的基本使用

    © 版权声明:本文为博主原创文章,转载请注明出处 1. 版本 SpringBoot:2.0.0.RELEASE 2. 集成 SpringBoot集成actuator模块非常简单,只需要引入actuat ...

  4. maven的一些基础命令

    1.显示当前构建的实际pom,包括活动的Profile mvn help:effective-pom 2.打印出项目的世界settings,包含从全局的settings和用户级别settings继承的 ...

  5. python 中的"switch"用法

    转载:http://python.jobbole.com/82008/ 为什么Python中没有Switch/Case语句? 不同于我用过的其它编程语言,Python 没有 switch / case ...

  6. C语言学习笔记(七)——其它运算符

     第七章                          其它运算符   逗号运算符 逗号运算符:即顺序点,逗号前先运行.后再运行. for循环的运行次数: for(i=n; i<m; + ...

  7. 《TomCat与Java Web开发技术详解》(第二版) 第四章节的学习总结--常用Servlet API

    要开发Servlet,自然要掌握常用的servlet的相关API.通过此章节的学习,了解到如下常用API 1.Servlet接口--->GenericServlet抽象类(实现Servlet接口 ...

  8. 【转】【Python学习】之哪些 Python 库让你相见恨晚?

    感谢作者:赖明星 文章链接地址:<哪些 Python 库让你相见恨晚?>

  9. laravel学习之路2: jwt集成

    "tymon/jwt-auth": "^1.0@dev", 执行 composer update 'providers' => [ .... Tymon\ ...

  10. 浅谈 MVP in Android(转)

    我自己写的demo:https://pan.baidu.com/s/1dFImVYD 一.概述 对于MVP(Model View Presenter),大多数人都能说出一二:“MVC的演化版本”,“让 ...