题目

这道题是个水题,写博客上的人好像都不屑于写这这道题。但是我为什么还是觉得挺难的呢? 我也是看了别人的博客才过了的,感觉这种写法很新颖,这样就可以不用在排序了。
下面给出正解:
#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的更多相关文章

  1. POJ 2591 1338 2545 2247(数列递归衍生问题,思路挺妙)

    四道题的难度: 2591<1338<2545<2247 POJ 2591 Set Definition: 这是从discuss里看来的,写的挺好,直接copy,根据我的代码稍有改动( ...

  2. POJ 2591

    #include<iostream> #include<stdio.h> #define MAXN 10000001 using namespace std; int a[MA ...

  3. POJ 2545+2591+2247+1338简单水题

    [题意简述]:就是有这种一个序列.就拿当p1 = 2,p2 = 3, p3 = 5,来举例.由这三个数为基准组成的序列是: 2,3,4,5,6,8,9,10,12--如今给你这个序列数组的下标,让你求 ...

  4. POJ - 1245 Programmer, Rank Thyself

    POJ - 1245 Programmer, Rank Thyself Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d  ...

  5. POJ 1308&&HDU 1272 并查集判断图

      HDU 1272 I - 小希的迷宫 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  6. POJ 1142 Smith Numbers(史密斯数)

    Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...

  7. poj 1679 The Unique MST

    题目连接 http://poj.org/problem?id=1679 The Unique MST Description Given a connected undirected graph, t ...

  8. POJ 1679 The Unique MST (最小生成树)

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22668   Accepted: 8038 D ...

  9. 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 ...

随机推荐

  1. intellij idea 的安装与简单使用

    1.将安装包拷贝到指定目录,特别注意不要有中文路径和空格,路径不要太深 2.点击安装(如果是win10系统要使用管理员权限安装)       3. 4.修改默认安装目录:一般来说我们都不要把软件安装在 ...

  2. 8.String to Integer (atoi) (INT; Overflow)

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  3. PAT L3-008 喊山(广搜)

    喊山,是人双手围在嘴边成喇叭状,对着远方高山发出“喂—喂喂—喂喂喂……”的呼唤.呼唤声通过空气的传递,回荡于深谷之间,传送到人们耳中,发出约定俗成的“讯号”,达到声讯传递交流的目的.原来它是彝族先民用 ...

  4. Excel日期格式调整

    3-Aug-2008   自定义格式: [$-809]d-mmm-yyyy;@ Aug-2008   自定义格式: [$-809]mmm-yyyy;@

  5. OC 线程操作 - GCD使用 - 栅栏函数

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //同步函数无需栅栏函数 //栅栏 ...

  6. 在CentOS7上部署Kubernetes集群

    在CentOS7上部署Kubernetes集群 文/FCBusquest 2015-12-22 18:36:00 简介 Kubernetes(k8s)是Google开源的大规模容器集群管理系统, 本文 ...

  7. 【深度好文】多线程之WaitHandle-->派生-》Mutex信号量构造

    bool flag = false; System.Threading.Mutex mutex = new System.Threading.Mutex(true, "Test", ...

  8. WPF之DataGrid控件根据某列的值设置行的前景色(色

    一种方法是 使用 datagrid的LoadingRow事件: private void DataGrid_LoadingRow(object sender, DataGridRowEventArgs ...

  9. wdk Windows驱动开发

    https://www.cnblogs.com/liaoguifa/p/9049859.html 安装wdk8.1

  10. Mockplus是如何节省你的原型时间的?

    还在用老牌原型工具一点点绘制产品原型吗?还在为实现一个满意的交互而绞尽脑汁吗?还在为无法和用户高效沟通而发愁吗?朋友,现在是快速原型的时代了.时间不等人,当你精雕细琢完成产品启动页的时候,别人的原型已 ...