C. Sequence

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100114

Description

Integer sequences are very interesting mathematical objects. Let us examine a sequence generated with the use of two operations: doubling and “digit sorting”. The latter operation consists in ascending-order sort of the individual digits in the decimal representation of the argument. For example, “digit sorting” of number 5726 gives 2567. The first member of the considered sequence is 1. To generate a member of the sequence from the previous member, double the previous one and apply “digit sorting” to the result. The first 15 members of the sequence are as follows: 1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156, … Write a program to determine the value of the n-th member of this sequence.

Input

The first line contains an integer n, the number of sequence member to be calculated.

Output

The output file should contain a single integer k, the value of the n-th member of the sequence

Sample Input

1

Sample Output

1

HINT

1 ≤ n ≤ 2 147 483 647.

题意

1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156

规律是上一个,是前一个数乘以2之后,数字按字典序排列之后的样子

题解:

打表之后,发现后面都是6个一个循环的,直接输出就好了

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm> using namespace std; int a[]={,,,,,,,,,,,,,,,,,,,,,,,,};
int b[]={,,,,,};
int n; int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&n);
if(n<=) printf("%d\n",a[n]);
else printf("%d\n",b[(n-)%]);
return ;
}

Codeforces GYM 100114 C. Sequence 打表的更多相关文章

  1. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

  2. Codeforces GYM 100114 D. Selection 线段树维护DP

    D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...

  3. codeforces GYM 100114 J. Computer Network 无相图缩点+树的直径

    题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” ...

  4. codeforces GYM 100114 J. Computer Network tarjan 树的直径 缩点

    J. Computer Network Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Des ...

  5. Codeforces GYM 100114 B. Island 水题

    B. Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description O ...

  6. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  7. Codeforces Gym 100418K Cards 暴力打表

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  8. Codeforces Gym 100114 D. Selection

    Description 问选择一个序列上的所有数的最少操作次数,跟电脑上选择文件一样,输出操作方案. Sol 贪心. 用Shift一段文件只能使用一次,之后必须一直按Ctrl了. 然后就是看用Shif ...

  9. Codeforces Gym 100114 J. Computer Network

    Description 给出一个图,求添加一条边使得添加后的图的桥(割边)最少. Sol Tarjan. 一遍Tarjan求割边. 我们发现连接的两个点一定是这两个点之间的路径上的桥最多,然后就可以贪 ...

随机推荐

  1. Android SDK Manager 更新代理配置 ,蛋碎了

    启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Settings』窗口: 在『Andro ...

  2. msssql 用numberic(38)替代int去解决int不够的问题

    发现ms sql server的问题int(-2^31 ~ 2 ^ 31 -1)与程序中的UINT有时会对不上的时候, 发现如果用numberic(32)来做判断好像解决, 暂时就现在的插入操作来看, ...

  3. link 参数

    -all-static do not do any dynamic linking at all -avoid-version do not add a version suffix if possi ...

  4. POJ 1094 Sorting It All Out

    题意:给出m对关于n个字母的小于关系,输出通过这些关系能得到的结论,如果可以排序就输出至少知道第几个关系时就可以知道顺序,从小到大输出顺序:如果产生歧义就输出在第几个关系时出现歧义,如果不能得出准确的 ...

  5. php-PHP试题

    ylbtech-doc:php-PHP试题 PHP试题 1.A,PHP试题返回顶部 1.{PHP题目}标识符是变量的名称.PHP中的标识符用“$+变量名”来表示.标识符在PHP中遵循下列选项中的那些规 ...

  6. [转]Oracle 阳历转农历

    CREATE TABLE SolarData ( YearID INTEGER NOT NULL, -- 农历年 DATA ) NOT NULL, -- 农历年对应的16进制数 DataInt INT ...

  7. duilib底层机制剖析:窗体类与窗体句柄的关联

    转载请说明原出处,谢谢~~ 看到群里朋友有人讨论WTL中的thunk技术,让我联想到了duilib的类似技术.这些技术都是为了解决c++封装的窗体类与窗体句柄的关联问题. 这里是三篇关于thunk技术 ...

  8. STL六大组件之——仿函数偷窥

    仿函数(functor),就是使一个类或类模板的使用看上去象一个函数.其实现就是类或类模板中对operator()进行重载,这个类或类模板就有了类似函数的行为.仿函数是智能型函数就好比智能指针的行为像 ...

  9. Leave Morningstar

    Today, closed 4++ years developer life (2009.11.17-2014.02.28) in MorningStar Shenzhen Office Austra ...

  10. lighttpd为什么要accept多次呢

    在lighttpd网络模型里面我们可以看到以下代码 /* accept()s at most 100 connections directly * * we jump out after 100 to ...