标签:
Description
Input
Output
Sample Input
Sample Output
#include <iostream>
#include <cstring>
#include <list>
const int maxn=5000+5;
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
int n, a[maxn];
memset(a, 1, sizeof(a));
scanf("%d",&n);
for (int i = 1; i <= n; i++)
a[i] = i;
int k = n;
int loge = 2;
while (k > 3)
{
int q = 0;
if (loge == 2)
{
for (int i = 1; i <= n; i++)
if (a[i] != 0 && ++q == 2)
{
q = 0;
a[i] = 0;
k--;
}
loge = 3;
}
else
{
for (int i = 1; i <= n; i++)
if (a[i] != 0)
{
if (a[i] != 0 && ++q == 3)
{
q = 0;
a[i] = 0;
k--;
}
}
loge = 2;
}
}
loge = 1;
for (int i = 1; i <= n; i++)
if (a[i] != 0)
if (loge)
{
cout << i;
loge = 0;
}
else
cout << ‘ ‘ << i;
cout << endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/xl1164191281/p/4676430.html