poj 1032 Parliament 【思维题】
题目地址:http://poj.org/problem?id=1032
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 17473 | Accepted: 7371 |
Description
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
Output
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 【思维题】的更多相关文章
- (Relax 水题1.2)POJ 1032 Parliament(将n分解成若干个互不相等的整数的和,并且是这些整数的乘积最大)
题意:给出一个数n,将其拆分为若干个互不相等的数字的和,要求这些数字的乘积最大. 分析:我们可以发现任何一个数字,只要能拆分成两个大于1的数字之和,那么这两个数字的乘积一定大于等于原数.也就是说,对于 ...
- Poj 1032 Parliament
Parliament Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19103 Accepted: 8101 Descr ...
- 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 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- 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 ...
随机推荐
- Yandex.Algorithm 2011 A. Double Cola
1.题目描写叙述:点击打开链接 2.解题思路:本题是一道找规律的数学题,通过题意描写叙述不难知道,相当于有5棵二叉树构成了一个森林,须要你按层次遍历找到第n个人是谁. 观察后不难发现,如果最開始的一层 ...
- 使用Fiddler抓包拦截线上JS
第三方教程:http://www.lcgod.com/atc_74 分六步即可: 1.左侧session列表中选中你想替换的一条请求 2.右侧,切换到AutoResponder,点击Add rules ...
- sgu101-欧拉回路
101. Domino time limit per test: 0.25 sec. memory limit per test: 4096 KB Dominoes – game played wi ...
- atititi.soa 微服务 区别 联系 优缺点.doc
atititi.soa 微服务 区别 联系 优缺点.doc 1. 应用微服务的动机,跟传统巨石应用的比较1 2. 面向服务架构(SOA) esb2 3. 微服务架构(Microservices)2 ...
- 网络相关系列之四:数据解析之SAX方式解析XML数据
一.XML和Json数据的引入: 通常情况下.每一个须要訪问网络的应用程序都会有一个自己的server.我们能够向server提交数据,也能够从server获取数据.只是这个时候就有一个问题,这些数据 ...
- ROS多个网段做隔离
ROS路由器有多个LAN口,网段分别是 192.168.0.0/24 和 192.168.1.0/24. 用192.168.1.0/24做为访客使用,因此在路由器上面设置过滤器. /ip firewa ...
- Effective C++ Item 34 区分接口继承与实现继承
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 关联条款 Item 36 接口继承和实现继承不同.在 public 继承下, derived ...
- Win7 设置、访问共享文件夹
一.设置共享文件夹 右键点击文件夹,打开“属性”窗口,选择“共享”选项卡 点击“共享”按钮,打开“文件共享”窗口,在下拉列表中选择账户,点“添加”,最后点“共享”按钮. 二.访问 \\192.168. ...
- Robot Motion - poj 1573
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11269 Accepted: 5486 Description A ...
- vue实践---vue不依赖外部资源实现简单多语
vue使用多语,最常见的就是 vue-i18n, 但是如果开发中的多语很少,比如就不到10个多语,这样就没必要引入vue-i18n了, 引入了反正导致代码体积大了,这时候单纯用vue实现多语就是比较好 ...