[恢]hdu 1276
2011-12-25 19:32:54
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1276
题意:中文。
mark:链表。用的静态的。
代码:
# include <stdio.h>
# include <memory.h>
int node[5010][2] ;
void init (int n)
{
int i ;
for (i = 0 ; i <= n; i++)
{
node[i][0] = i ;
node[i][1] = i+1 ;
}
node[0][0] = n ;
node[n][1] = 0 ;
}
void del(int m)
{
int p = 0, q = 1, cnt = 1 ;
while (q)
{
if (cnt == m)
{
node[p][1] = node[q][1] ;
node[q][0] = 0 ;
cnt = 0 ;
node[0][0]-- ;
}
p = q ;
q = node[q][1] ;
cnt++ ;
}
}
int main ()
{
int T, n, i ;
int tab[] = {2, 3}, flag = 0 ;
scanf ("%d", &T) ;
while (T--)
{
scanf ("%d", &n) ;
init (n) ;
flag = 0 ;
while (node[0][0] > 3)
{
del(tab[flag]) ;
flag = !flag ;
}
flag = 0 ;
i = node[0][1] ;
while (i != 0)
{
if (flag == 0) flag = 1 ;
else printf (" ") ;
printf ("%d", i) ;
i = node[i][1] ;
}
printf ("\n") ;
}
return 0 ;
}