poj2552

打表

View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;

#define maxn 35005

int n;
int pre[maxn], next[maxn];

void del(int a)
{
pre[next[a]] = pre[a];
next[pre[a]] = next[a];
}

void init()
{
n = 35000;
for (int i = 0; i < n; i++)
{
pre[i + 1] = i;
next[i] = i + 1;
}
next[n] = -1;
del(1);
}

void work()
{
int cnt = 0;
while (cnt < 3000)
{
cnt++;
int i = next[0];
printf(",%d", i);
int a = i;
del(i);
int x = 0;
while (next[i] != -1)
{
i = next[i];
x++;
if (x % a == 0)
del(i);
}
}
}

int main()
{
freopen("t.txt", "w", stdout);
init();
work();
return 0;
}

你可能感兴趣的:(poj)