sequence 这个算……找规律的题吧
来源:互联网 发布:免费广告配音软件 编辑:程序博客网 时间:2024/04/29 03:14
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. (1<=n<= 2 147 483 647)
Output
The output file should contain a single integer k, the value of the n-th member of the sequence.
Sample Input
16Sample Output
123
是个水题,但是刚开始的时候完全没有发现到后面的数是一样的,所以纠结了很久……罚时很高的说……。所以碰到范围特别大的题,很可能存在小tipppp。然后就是在处理数字和字符的时候会有一点小技术吧。
#include <stdio.h>#include <iostream>#include <algorithm>#define maxn 2300using namespace std;__int64 n;char s[maxn];int a[27];int b[6]={155578,111356,122227,244445,48889,77789};int comp(char a,char b){ return a>b;}void go(){ int i,j,k; int p,q,r,x,y; a[1]=1; for(i=2;i<=26;i++) { a[i]=a[i-1]*2; p=a[i]; q=p%10; r=p/10; x=0; while(q||r) { s[x++]=q+'0'; q=r%10; r=r/10; } sort(s,s+x,comp); s[x]='\0'; a[i]=0; while(x--) { a[i]=a[i]*10+s[x]-'0'; } }}int main(){ go(); while(scanf("%d",&n)!=EOF) { if(n<=26 ) printf("%d\n",a[n]); else { printf("%d\n",b[(n-27)%6]); } } return 0;}
- sequence 这个算……找规律的题吧
- Number Sequence 找规律
- HDUOJ Number Sequence找规律
- hdoj1005 Number Sequence(找规律)
- Codeforces Round #182 (Div. 2)---C. Yaroslav and Sequence(不错的题,分析找规律)
- poj 1019 Number Sequence 找规律 思维题 ()
- 一道找规律的题
- uva10706 - Number Sequence(找规律)
- hdu1005 Number Sequence (找规律)
- uva 10706 Number Sequence(找规律)
- hdu 1005 Number Sequence(找规律)
- LeetCode-60-Permutation Sequence(找规律)-Medium
- [DP 找规律] BZOJ2489 Random Sequence
- Number Sequence 【打表】+【找规律】
- HDU 1005 Number Sequence(找规律)
- HDU 1005-Number Sequence(找规律)
- HDU 1005 Number Sequence 找规律
- hdu 1005 Number Sequence(找规律)
- 机房收费系统之无法附加数据库
- Ant+JUnit+Cobertura执行测试用例时,应注意的问题(以Apache POI为例)
- ZOJ-1247
- POJ 2828 Buy Tickets
- 线段树特殊懒惰标记hdu3954(hdu4902)
- sequence 这个算……找规律的题吧
- uva10404 - Bachet's Game(博弈,递推)
- Libevent源码分析-----多线程、锁、条件变量(二)
- LDA
- 如何提升程序员的“性能”
- Conclusion of these days
- 节点关系及节点操作方法
- .net html去除顶部空隙或多余的border
- 如何测试一个U盘