hdu 6130 Kolakoski
来源:互联网 发布:mac 查看磁盘剩余空间 编辑:程序博客网 时间:2024/06/05 20:49
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
Source
2017 Multi-University Training Contest - Team 7
Recommend
liuyiding | We have carefully selected several similar problems for you: 6216 6215 6214 6213 6212
题意:给两组数,两组数都只由1、2组成,上边那组数对应位置的数字是下边那组数的对应位置的数字的个数,而下边那组数拆开后和上边的数完全一样。
刚开始做的时候意味着两组数之后的数是有一定规律的,推了半天的规律,没找到,然后又看了一下给的数的范围和时间,然后就用模拟过了........
直接按照题目给的规律模拟,我是用的队列来模拟的。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<queue>using namespace std;typedef long long ll;int main(){int T;ll m,n,a,b;scanf("%d",&T);while(T--){queue<ll> q;scanf("%lld",&n);if(n==1){printf("1\n");}else if(n==2){printf("2\n");}else if(n==3){printf("2\n");}else{n-=3;q.push(2);while(n--){ll w=q.back();ll t=q.front();if(t==1&&w==1){q.push(2);q.pop();}else if(t==1&&w==2){q.push(1);q.pop();}else if(t==2&&w==2){q.push(1);q.push(1);q.pop();}else if(t==2&&w==1){q.push(2);q.push(2);q.pop();}}printf("%lld\n",q.front());}}return 0;}
阅读全文
0 0
- HDU 6130-Kolakoski(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
- HDU 6130 Kolakoski 打表
- HDU 6130 Kolakoski(数学)
- HDU 6130 Kolakoski【找规律】
- QT之编译源码-数据库加密
- web技术基础_其实只是期中复习
- 日期类的实现
- .c/.cpp文件形成.exe文件的过程
- bzoj1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
- hdu 6130 Kolakoski
- 非maven项目将第三方依赖打入jar
- js实现的冒泡排序、选择排序、插入排序、快速排序
- MvP+recyclerview
- MongoDB:20-MongoDB- 正则表达式
- C# 局部函数与事件
- 通过异步过程调用(APC)注入DLL
- 网路编程技术
- 日常的一些八阿哥