构造队列

来源:互联网 发布:家族企业 知乎 编辑:程序博客网 时间:2024/05/14 02:47

方向模拟:

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int a[100005];int main(){    int t;scanf("%d",&t);    while(t--){        int low = 0, high = 0;        int n;scanf("%d",&n);        a[high++] = n;        int mod = n+2;        for(int i=n-1;i>=1;i--){            a[high] = i;            high = (high +1)% mod;            a[high] = a[low];             high = (high + 1)%mod, low = (low+1)%mod;        }        int ind = (low-1+n)%mod;// 一个数字重复        for(int i=low;i<low+n-1;i++){            printf("%d ",a[ind]);            ind = (ind - 1 + mod)%mod;        }        printf("%d\n",a[ind]);    }    return 0;} 
0 0