Codeforces GYM 100114 C. Sequence 打表
2015-09-03 19:05
585 查看
C. Sequence
Time Limit: 1 SecMemory Limit: 256 MB
题目连接
http://codeforces.com/gym/100114Description
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 sequenceSample Input
1Sample Output
1HINT
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[40]={0,1,2,4,8,16,23,46,29,58,116,223,446,289,578,1156,1223,2446,2489,4789,5789,11578,12356,12247,24449}; int b[10]={48889,77789,155578,111356,122227,244445}; int n; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%d",&n); if(n<=24) printf("%d\n",a ); else printf("%d\n",b[(n-25)%6]); return 0; }
相关文章推荐
- Access restriction: The type * is not accessible due to restrict,报错问题
- 在Closing事件中,将e.Cancle设置成true,则Windows无法关机和重启系统的解决办法
- poj 2299 Ultra-QuickSort(树状数组)
- 2012-2013 ACM-ICPC, NEERC, Central Subregional Contest C Sequence (打表)
- 一篇讲得非常好的build模式的解释文章
- maven -- 问题解决(二)解决“Could not calculate build plan”问题
- STL vector, deque, list对比
- [刷题]Implement Queue by Two Stacks
- 九度OJ 题目1119:Integer Inquiry
- 让UITextView文字垂直居中
- UITextFiledView页面之间的相互传值
- Android UI设计(引导界面):ViewPager之三PagerTabStrip与PagerTitleStrip添加标题栏的区别
- jquey.fullpage详解
- UINavigaionController中的传值(协议)
- Android UI设计——ViewPage的无限循环(五)
- Arduino LM35温度检测
- RYU的GUI安装
- 黑马程序员—————Java基础--------GUI
- Android UI设计——ViewPage中自定义标题栏(四)
- UI触屏的操作初识