我们来枚举一下,当传球次数达到 次时,队列回到原样,样例二验算一下就会发现是正确的。
根据这条思路我们就可以将 对 取模,剩下的部分考虑枚举,用双端队列分别维护左边和右边,最后按照题目进行模拟。
代码
#include<bits/stdc++.h>
using namespace std;
deque<int> q1,q2;
long long k,n,m,ans;
int main()
{
int T;
cin>>T;
while(T--)
{
q1.clear();q2.clear();
scanf("%lld%lld%lld",&n,&m,&k);
k%=(n*2),ans=n/2+1;
for(int i=1;i<=n/2;i++) q1.push_back(i);
for(int i=n/2+2;i<=n;i++) q2.push_back(i);//初始化队列
for(int i=1;i<=k;i++)
{
if(m)
{
q2.push_back(ans);
ans=q2.front();
q2.pop_front();
m=0;
}
else
{
q1.push_front(ans);
ans=q1.back();
q1.pop_back();
m=1;
}
}
while(!q1.empty())
{
printf("%d ",q1.front());
q1.pop_front();
}
printf("%lld ",ans);
while(!q2.empty())
{
printf("%d ",q2.front());
q2.pop_front();
}
printf("\n");//记得加换行
}
return 0;
}