Kolakoski(思维+找规律)
来源:互联网 发布:电子商城源码 编辑:程序博客网 时间:2024/06/13 06:18
Kolakoski
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
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…… . This sequence consists of 1 and 2 , and its first term equals 1 . 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 n th element.
Input
The first line contains a positive integer T(1≤T≤5) , denoting the number of test cases.
For each test case:
A single line contains a positive integern(1≤n≤107) .
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.
A single line contains a nonnegative integer, denoting the answer.
Sample Input
212
Sample Output
12#include<cstdio>#include<iostream>using namespace std;int a[10000010];int main(){int n,t;scanf("%d",&t);while(t--){scanf("%d",&n);a[1]=1;int pre=2;int p=1;for(int i=1;p<10000010;i++){pre=3-pre;if(a[i]==1){a[p++]=pre;}else{a[p++]=pre;a[p++]=pre;}}printf("%d\n",a[n]);}}
阅读全文
0 0
- Kolakoski(思维+找规律)
- HDU 6130 Kolakoski【找规律】
- HDU6130 Kolakoski 模拟|找规律|签到
- 思维、找规律题目汇总
- HDU 6048 思维+找规律
- HDU_6130 Kolakoski 【规律】
- UESTC 1012 (思维)(找规律)
- codeforces-141【B找规律】【C思维】
- codeforces-743【B找规律】C思维】
- Beehive UVALive - 7528 (找规律+数学思维)
- hdu4572_Bottles Arrangement_(思维+找规律)
- hdu6130-多校7&规律-Kolakoski
- codeforce 9C 找规律的思维题
- poj 1019 Number Sequence 找规律 思维题 ()
- HDU 1391 Number Steps(思维题目,找规律)
- HDU 1005 Number Sequence(找规律,思维)
- 玲珑学院-1010-Alarm【打表】【找规律】【思维】
- lightoj 1010 - Knights in Chessboard (找规律思维)
- TensorFlow深度学习入门——Win10下安装Tensorflow和GPU加速
- android stadio集成React-native
- iOS UITabBarController
- maven install时自动施行单元测试
- 信号和槽
- Kolakoski(思维+找规律)
- [RK3288][Android6.0] 调试笔记 --- 读取cmd_type失败
- vue-resource全攻略
- javaday15-IO(整理和训练)
- HDU2053 Switch Game
- NTP和RTP时间戳
- 为什么还是说信息没填写完整呢
- 汉诺塔问题
- Proc