传送门UVa 11129 - An antiarithmetic permutation
题意:找出一个序列,从左到右不能有三个数的等差数列。
没思路,参考了shuangde800的解题报告。
#include <cstdio>
using namespace std;
const int MAXN = 11000;
int init[MAXN], ans[MAXN];
void Resolve(int left, int right)
{
int i;
if (left == right)
return;
int k = left;
for (i = left; i <= right; i += 2)
ans[k++] = init[i];
for (i = left + 1; i <= right; i += 2)
ans[k++] = init[i];
for (i = left; i <= right; i++)
init[i] = ans[i];
Resolve(left, (left + right) / 2);
Resolve((left + right) / 2 + 1, right);
}
int main()
{
//freopen("input.txt", "r", stdin);
int T, n, i, j;
while (scanf("%d", &n), n)
{
for (i = 0; i < n; i++)
init[i] = i;
Resolve(0, n - 1);
printf("%d:", n);
for (i = 0; i < n; i++)
printf(" %d", ans[i]);
printf("\n");
}
return 0;
}