HDU 6130 Kolakoski(数学)
来源:互联网 发布:mac诸星团最后去了哪里 编辑:程序博客网 时间:2024/05/29 07:58
Kolakoski
2017 Multi-University Training Contest - Team 7
题目链接
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 281 Accepted Submission(s): 122
Problem Description
This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1,2,1,1,2,1,2,2,1,1. This sequence consists of and , and its first term equals . Besides, if you see adjacent and equal terms as one group, you will get 1,22,11,2,1,22,1,22,11,2,11,22,1……. . Count number of terms in every group, you will get the sequence itself. Now, the sequence can be uniquely determined. Please tell HazelFan its th element.
Input
The first line contains a positive integer , denoting the number of test cases.
For each test case:
A single line contains a positive integer .
Output
For each test case:
A single line contains a nonnegative integer, denoting the answer.
Sample Input
2
1
2
Sample Output
1
2
Source
2017 Multi-University Training Contest - Team 7
Recommend
liuyiding
一道数学题
Kolakoski序列
Kolakoski序列是一个仅由1和2组成的无限数列,是一种通过“自描述”来定义的数列[1] 。
他的前几项为
1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1,2,1,1,2,1,2,2,1,1,…(OEIS上的A000002)
它的定义很简单,若把数列中相同的数定为一组,令a(1)=1,a(2)=2,则a(n)等于第n组数的长度。
可以根据这个定义来推算第三项以后的数:例如由于a(2)=2,因此第2组数的长度是2,因此a(3)=2,;
由于a(3)=2,所以第三组数的长度是2,因此a(4)=a(5)=1;由于a(4)=1,a(5)=1,所以第四组数和第五组数的长度都为1,因此a(6)=2,a(7)=1,以此类推。
模拟打表暴力求解
具体看代码吧。
#include<cstdio>#include<cstring>using namespace std;int a[10000007];int main(){ a[1]=1; a[2]=2; int n=2; for(int i=2;i<10000007;) { int num; num=a[n++]; if(n%2==1) { for(int j=1;j<=num;j++) { a[i++]=2; } } else { for(int j=1;j<=num;j++) { a[i++]=1; } } } int T,x; scanf("%d",&T); while(T--) { scanf("%d",&x); printf("%d\n",a[x]); } return 0;}
- HDU 6130 Kolakoski(数学)
- HDU 6130-Kolakoski(Kolakoski序列)
- hdu 6130 Kolakoski (水题)
- HDU 6130 Kolakoski(水~)
- 【HDU 6130 Kolakoski】& Kolakoski & 打表
- hdu 6130 Kolakoski(多校联赛)
- hdu-6130-Kolakoski
- HDU 6130 Kolakoski
- HDU 6130 Kolakoski
- HDU 6130-Kolakoski
- hdu-6130-Kolakoski
- hdu 6130 Kolakoski
- hdu 6130 Kolakoski
- HDU 6130 Kolakoski数列
- hdu 6130 Kolakoski
- HDU 6130 Kolakoski【】
- HDU 6130 Kolakoski
- HDU 6130 Kolakoski
- samba
- 巴蜀oj1939(RMQ 的例题 )
- linux下的一些常用命令整理
- 廖雪峰Python教程阅读笔记——2. Python函数
- xcode 代码前不显示行数,解决方法
- HDU 6130 Kolakoski(数学)
- 8-15 DAIRY
- HDU 1016 (Prime Ring Problem)
- Python numpy函数hstack() vstack() stack() dstack() vsplit() concatenate()
- Hdu6127 Hard challenge(2017多校第7场)
- 递归与动态规划---跳跃游戏
- 通过JDBC访问数据库
- 刷题——Stripies POJ
- spring boot集成activemq