hdu 6130 Kolakoski
2017-10-30 20:52
357 查看
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 nth
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 integer n(1≤n≤107).
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 | 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;
}
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 nth
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 integer n(1≤n≤107).
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 | 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;
}
相关文章推荐
- 17暑假多校联赛7.11 HDU 6130 Kolakoski
- HDU 6130 Kolakoski 打表
- HDU_6130 Kolakoski 【规律】
- 多校7 HDU-6130 Kolakoski 构造数列 & 模拟
- hdu 6130 Kolakoski
- HDU 6130 Kolakoski(水~)
- HDU 6130 Kolakoski(数学)
- HDU 6130 Kolakoski【】
- 2017杭电多校第七场1011 Kolakoski(签到题)HDU 6130
- HDU 6130 Kolakoski
- hdu-6130-Kolakoski
- hdu 6130 Kolakoski(多校联赛)
- hdu 6130 Kolakoski - 多校联盟7
- HDU 6130 Kolakoski
- HDU 6130 Kolakoski【找规律】
- hdu-6130-Kolakoski
- HDU 6130-Kolakoski(Kolakoski序列)
- hdu 6130 Kolakoski
- HDU 6130 Kolakoski(构造序列)
- 【HDU 6130 Kolakoski】& Kolakoski & 打表