hdu 6130 _数学规律
来源:互联网 发布:cpu温度检测软件 编辑:程序博客网 时间:2024/05/01 00:24
Kolakoski
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
按Kolakoski数列规律模拟就好
#include<iostream>#include<cstdio>#include<cstring>#include<map>typedef long long ll;using namespace std;const ll N=(ll)1e7+1;ll num[N]= {0,1,2,2};int main(){ ll i,j,t,n,k=3; for(i=3; k<N; i++) { if(num[i]==2) { if(num[k]==2) { num[k+1]=1; num[k+2]=1; } else { num[k+1]=2; num[k+2]=2; } k+=2; } else { if(num[k]==1) num[k+1]=2; else num[k+1]=1; k+=1; } } scanf("%lld",&t); while(t--) { scanf("%lld",&n); printf("%lld\n",num[n]); } return 0;}
- hdu 6130 _数学规律
- hdu 4342 数学规律
- hdu 5587(数学规律)
- hdu 2086 数学规律
- HDU 1046 数学规律题
- HDU--5312(规律+数学)
- HDU 1722 Cake【规律+数学】
- hdu-1220(数学规律)
- 数学 找规律HDU-1030
- 【数学期望 && 找规律】HDU
- hdu 1060_数学
- HDU 4279(数学+找规律)
- HDU 1030 纯数学 找规律
- hdu 2114 找规律的数学题目
- HDU 3524 Perfect Squares 数学找规律
- hdu 5106 组合数学+找规律
- HDU 5826 physics (数学推导)(规律)
- 【规律】【贪心】【数学】HDU 5573 Binary Tree
- 新司机上路--如何在Typora中写Markdown
- 第七次多校联合hdu6130 Kolakoski
- 启动Nginx报[10013]错误的解决方案
- Mac端口占用
- freeswitch系列一 在debian中安装freeswitch1.6
- hdu 6130 _数学规律
- Android WallpaperManager
- Grunt的配置和使用
- hdu 6129 Just do it(递推)
- 1054: 猴子吃桃
- 《三体》读后思考-泰勒展开/维度打击/黑暗森林
- D
- 遍历数组 iterator方法和for方法
- 继承之构造器借用法