HDU6130 Kolakoski(模拟,2017 HDU多校联赛 第7场)
来源:互联网 发布:新生分班软件 编辑:程序博客网 时间:2024/05/18 02:19
题目:
Kolakoski
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 540 Accepted Submission(s): 281
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
Source
2017 Multi-University Training Contest - Team 7
Recommend
liuyiding | We have carefully selected several similar problems for you: 6132 6131 6130 6129 6128
关于这个数列的定义:Kolakoski序列
关于这个数列的推导:
首先我们定义:
a[n]代表第n组数的个数,把数列中相同的数定义为一组
首先给出a[1]=1,a[2]=2
因为a[2]=2,那么就证明第二组数有连续的两个2,那么数列现在是这样的
1 2 2
现在数列的a[3]位置变成了2,就证明这个数列后面要加两个1,也就是这样的:
1 2 2 1 1
现在a[4]=1,a[5]=1,我们就能推出a[6]=2,a[7]=1
做法就是模拟这个过程,打表~
但是不知道为啥奇数输出1,偶数输出2,也能AC
代码:
#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 1000007#define ll long longusing namespace std;const int N=1e7+5;int a[N];void init(){a[1]=1;a[2]=2;a[3]=2;int cnt=3;int flag=2;for(int i=4; i<N;){int num=a[cnt];for(int j=0; j<num; j++){if(flag==2)a[i]=1;elsea[i]=2;if(j==num-1) flag=a[i];i++;}cnt++;}}int main(){init();int t,n;scanf("%d",&t);while(t--){scanf("%d",&n);printf("%d\n",a[n]);}return 0;}
阅读全文
0 0
- HDU6130 Kolakoski(模拟,2017 HDU多校联赛 第7场)
- hdu6130 Kolakoski 2017多校第七场1011 打表
- Hdu6130 Kolakoski(2017多校第7场)
- HDU6077 Time To Get Up(模拟,2017 HDU多校联赛 第4场)
- HDU6168 Numbers(模拟,2017 HDU多校联赛 第9场)
- HDU6168 Numbers(模拟,2017 HDU多校联赛 第9场)
- hdu 6130 Kolakoski(多校联赛)
- hdu6130-多校7&规律-Kolakoski
- 17暑假多校联赛7.11 HDU 6130 Kolakoski
- HDU6130 Kolakoski 模拟|找规律|签到
- hdu6130--Kolakoski
- HDU6130 Kolakoski
- HDU6130-Kolakoski
- HDU6130-Kolakoski
- hdu 4627 (多校联赛第3场1008)
- HDU6047 Maximum Sequence(贪心,2017 HDU多校联赛 第2场)
- HDU6055 Regular polygon(计算几何,2017 HDU多校联赛 第2场)
- HDU6045 Is Derek lying?(规律,2017 HDU多校联赛 第2场)
- NodeJS+ExpressJS解决跨域请求CORS
- 代理模式之静态代理
- 微信小程序开发--表单验证
- java中使用json(org.json)
- 有关析构函数和构造函数的几点说明
- HDU6130 Kolakoski(模拟,2017 HDU多校联赛 第7场)
- HDU6127 Hard challenge 极角排序|暴力
- git用法
- JSP页面生成年份下拉框
- AS1.5升级AS2.23后无法正常编译APP到真机
- CSS之flexbox
- golang日志库
- C++调试传入参数
- 文本转化工具dos2unix