Sicily 1934 移动小球

题目地址 http://sicily.3322.org/problem_status.php?pid=1934&p=1

此题参考了秋叶飘零的博客 http://adonis0147.blog.163.com/blog/static/162553854201061410316118/ 所以也就没什么好说的了, 秋叶同学做得很好呀~

代码
#include <stdio.h>
#define MAXN 500010
#define MAXM 100000

int main()
{
int t, n, m;
int i, counter, ptr;
int cmd, from, to;
int prev[MAXN], next[MAXN];

scanf(
"%d", &t);
while(t--)
{
scanf(
"%d%d", &n, &m);
for(i = 0; i <= n; i++)
{
prev[i]
= i - 1;
next[i]
= i + 1;
}

while(m--)
{
scanf(
"%d%d%d", &cmd, &from, &to);

next[prev[from]]
= next[from];
prev[next[from]]
= prev[from];

if(cmd == 1)
{
prev[from]
= prev[to];
next[from]
= to;

prev[to]
= next[prev[to]] = from;
}
else
{
prev[from]
= to;
next[from]
= next[to];

next[to]
= prev[next[to]] = from;
}
}

i
= 0;
ptr
= next[0];
while(i < n)
{
printf(
"%d ", ptr);
ptr
= next[ptr];
i
++;
}
printf(
"\n");
}
return 0;
}

原文地址:https://www.cnblogs.com/platero/p/1877080.html