HDU6130 签到题 打表

LINK

题意:给出一个描述自身的数列,求出第n项

思路:看了很久题目才看懂..每个值其实是描述一个分组中的个数,把两个数列对照一下就可以了,那么一个指针扫,同时向尾部加数,构造个数组就行了。其实很水..

/** @Date    : 2017-08-15 12:13:59
  * @FileName: 1011.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e7+20;
const double eps = 1e-8;

int a[N] = {0, 1,2,2,1,1,2,1,2,2,1,2,2,1,   1, 2, 1, 1, 2, 2, 1};
int main()
{
	int cnt = 21;
	for(int i = 14; cnt <= 10000000; i++) {
		if(a[i] == 0)
			break;
		if(a[i] == 1) {
			a[cnt] = (3 - a[cnt - 1]);
			cnt++;
		}
		else if(a[i] == 2) {
			a[cnt] = (3 - a[cnt - 1]);
			a[cnt + 1] = (3 - a[cnt - 1]);
			cnt += 2;
		}
	}
	int T;
	cin >> T;
	while(T--)
	{
		int n;
		scanf("%d", &n);
		printf("%d
", a[n]);
	}
    return 0;
}
原文地址:https://www.cnblogs.com/Yumesenya/p/7392134.html