poj 2591 Set Definition
题目
#include<cstdio>
#include<iostream>
using namespace std;
int S[10000000+5];
int min(int a,int b)
{
return a<b? a:b;
}
int main()
{
int n,i;
int a =1, b = 1;
S[1] = 1;
for( i=2;i<=10000000;i++)
{
S[i] = min(S[a]*2+1,S[b]*3+1);
if(S[i] == S[a]*2+1 ) a++;
if(S[i] == S[b]*3+1 ) b++;
}
while(~scanf("%d",&n))
printf("%d\n",S[n]);
//while(cin>>n)
//cout<<S[n]<<endl;
return 0;
}
我拿到这道题的时候,就觉得把所有的数放到数组里面去就可以了,但是又犹豫数据量会不会太大了10000000,又不敢轻举妄动,总是我没写出来。。。
poj 2591 Set Definition的更多相关文章
- POJ 2591 1338 2545 2247(数列递归衍生问题,思路挺妙)
四道题的难度: 2591<1338<2545<2247 POJ 2591 Set Definition: 这是从discuss里看来的,写的挺好,直接copy,根据我的代码稍有改动( ...
- POJ 2591
#include<iostream> #include<stdio.h> #define MAXN 10000001 using namespace std; int a[MA ...
- POJ 2545+2591+2247+1338简单水题
[题意简述]:就是有这种一个序列.就拿当p1 = 2,p2 = 3, p3 = 5,来举例.由这三个数为基准组成的序列是: 2,3,4,5,6,8,9,10,12--如今给你这个序列数组的下标,让你求 ...
- POJ - 1245 Programmer, Rank Thyself
POJ - 1245 Programmer, Rank Thyself Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d ...
- POJ 1308&&HDU 1272 并查集判断图
HDU 1272 I - 小希的迷宫 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- POJ 1142 Smith Numbers(史密斯数)
Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...
- poj 1679 The Unique MST
题目连接 http://poj.org/problem?id=1679 The Unique MST Description Given a connected undirected graph, t ...
- POJ 1679 The Unique MST (最小生成树)
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22668 Accepted: 8038 D ...
- poj 1679 http://poj.org/problem?id=1679
http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
随机推荐
- go递归函数如何传递数组切片slice
数组切片slice这个东西看起来很美好,真正用起来会发现有诸多的不爽. 第一,数组.数组切片混淆不清,使用方式完全一样,有时候一些特性又完全不一样,搞不清原理很容易误使用. 第二,数组切片的appen ...
- CNN深度好文
https://www.zhihu.com/question/52668301/answer/194998098?utm_medium=social&utm_source=qq
- Hadoop 3.0.0-alpha1几个值得关注的特性
1.支持纠删码:意味着更灵活的存储策略,即经常使用的数据利用备份方式存储(3倍存储消耗),冷数据利用纠删码容错(1.4倍存储消耗,但会造成额外的IO及CPU消耗): 2.MapReduce任务支持本地 ...
- 微擎系统 微信支付 get_brand_wcpay_request:fail
支付授权目录问题,有一个是域名加app的
- collections系列之Counter
collections模块中有一个叫做Counter的类,该类的作用就是计数器,Counter是对dict的加工,所有Counter继承了dict的方法 1.创建一个Counter,需要import ...
- 移动端input验证只允许有数字 在safari浏览器一直不成功解决
<input class="lineHeight-30" type="text" onkeyup="value=value.replace(/[ ...
- 在iframe框架中全屏不好使的原因
遇到的问题:我是在iframe框架中添加了一个插件在360和火狐中不好使,将allowfullscreen="true" 属性配置好就没问题了: 可能出现的原因:将allowful ...
- python性能测试大致计划
hi guy: 如果注意到创建时间,那就对了.这份文章,是我学习Python一个月以后动手写的. 写下这份计划以后,只完成了第一步,其中磕磕绊绊编写代码的过程,很大一部分时间是完全用txt写的 ...
- dedecms连表查询参照
ixingmeib2c/ds/entity_clas/tc_coupon_index.ls.php下面的getIndexInfo()方法
- 编写JavaScript 代码的5个小技巧
1.Array.includes 与条件判断 一般我们判断或用 || // condition function test(fruit) { if (fruit == "apple" ...