OJ-Problems-Source/HDOJ/Multi-University Training Contest/2017/Team 7/1011_Richard_Kiritow.cpp

55 lines
1.3 KiB
C++
Raw Normal View History

2017-08-19 17:29:23 +08:00
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <bitset>
#include <algorithm>
std::vector<std::size_t> kolakoski(std::size_t size) {
std::vector<std::size_t> vec;
vec.reserve(size);
vec.push_back(1);
vec.push_back(2);
vec.push_back(2);
std::vector<std::size_t>::iterator it = vec.begin() + 2;
while (vec.size() < size) {
if (*it == 1) {
if (vec.back() == 1) {
vec.push_back(2);
}
else { //if (vec.back() == 2) {
vec.push_back(1);
}
}
else { //if (*it == 2) {
if (vec.back() == 1) {
vec.push_back(2);
vec.push_back(2);
}
else { //if (vec.back() == 2) {
vec.push_back(1);
vec.push_back(1);
}
}
++it;
}
return vec;
}
int main() {
int t;
int n[5];
int nmax = 0;
std::cin >> t;
for (int i = 0; i < t; i++) {
std::cin >> n[i];
nmax = std::max(n[i], nmax);
}
std::vector<std::size_t> vec = kolakoski((std::size_t)nmax);
//<2F>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>
for(int i=0;i<t;i++)
{
std::cout<<vec[n[i]-1]<<std::endl;
}
return 0;
}