【2017 Multi-University Training Contest - Team 7】Kolakoski
2017-10-04 18:44
567 查看
【Link】:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=765
【Description】
有一种数列叫Kolakoski:1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……,如果将这个数组相同的数字合并成一个新数列:1,22,11,2,1,22,1,22,11,2,11,22,1……,第二个数列中第几组数中的个数就是第一个数列中的第几个数。现在要求出第一个数列第n个数。
【Solution】
相邻的相同的数字的个数这个数列f的增长速度是没有原数列a的增长速度快的.
则对于新添加在a末尾的数字,看看它改变的相应的f值的最后一项是不是和a的相应的位置相同即可。
只有1和2两个数字,两个数字都试试就好.
这样就能处理出来整个数列了,O(1)输出就好。
【NumberOf WA】
0
【Reviw】
【Code】
#include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define mp make_pair #define pb push_back #define fi first #define se second #define ms(x,y) memset(x,y,sizeof x) #define ri(x) scanf("%d",&x) #define rl(x) scanf("%lld",&x) #define rs(x) scanf("%s",x+1) #define oi(x) printf("%d",x) #define ol(x) printf("%lld",x) #define oc putchar(' ') #define os(x) printf(x) #define all(x) x.begin(),x.end() #define Open() freopen("F:\\rush.txt","r",stdin) #define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii; typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1}; const int dy[9] = {0,0,0,-1,1,-1,1,-1,1}; const double pi = acos(-1.0); const int N = 110; int n,a[10000000+10]; int main(){ //Open(); //Close(); a[1] = 1; int j = 1; int now = 1; for (int i = 2;i <= 10000000+10;i++){ a[i] = a[i-1]; if (now + 1 != a[j]){ a[i] = 3 - a[i]; now = 1; j++; }else{ now++; } } int T; ri(T); while (T--){ int n; ri(n); oi(a ); puts(""); } return 0; }
相关文章推荐
- 2017 Multi-University Training Contest - Team 7 Kolakoski
- 2017 Multi-University Training Contest - Team 7:hdu6130、Kolakoski
- 2017 Multi-University Training Contest - Team 7 1011 Kolakoski
- 2017 Multi-University Training Contest - Team 7:1011. Kolakoski(模拟)
- 2017 Multi-University Training Contest - Team 9 Numbers (实力乱搞)
- HDU 6134 Battlestation Operational(基本数论+莫比乌斯反演)——2017 Multi-University Training Contest - Team 8
- HDU6033 & 2017 Multi-University Training Contest - Team 1 A
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- 2017 Multi-University Training Contest - Team 1 1006 Function
- 2017 Multi-University Training Contest - Team 1 & hdu6043 KazaQ's Socks
- hdu 6047 Maximum Sequence(2017 Multi-University Training Contest - Team 2)
- hdu 6045 Is Derek lying?(2017 Multi-University Training Contest - Team 2)
- 2017 Multi-University Training Contest - Team 2 的签到题
- HDU 6039 Gear up 2017 Multi-University Training Contest - Team 1 线段树维护到树根距离 区间修改 区间最值
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6055 简单计算几何,查找点的四种办法 2017 Multi-University Training Contest - Team 2
- 2017 Multi-University Training Contest - Team 2 - 1011
- 2017 Multi-University Training Contest - Team 1 HDU 6035 Colorful Tree
- 2017 Multi-University Training Contest - Team 2 - 1006
- 2017 Multi-University Training Contest - Team 1 1009 I Curse Myself 【思维 + 仙人掌图】