Skip to content

Pro2

原始文件为 CPP 代码,本文是转换后的 Markdown 文件。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;
const int maxn = 105;
const int maxt = 105;
const int maxL = 1005;
int pos[maxn];
int sta[maxL];
int clock[maxn];

int main()
{
    freopen("in.txt","r",stdin);
    int n,L,t;
    scanf("%d%d%d",&n,&L,&t);

    memset(sta,0,sizeof(sta));

    for (int i = 1; i <= n; ++i)
    {
        scanf("%d",&pos[i]);
        sta[pos[i]] = i;
        clock[i] = 1;
    }

    for (int i = 0; i < t; ++i)
    {       
        for (int j = 1; j <= n; ++j)
        {
            int other = sta[pos[j]];
            if (other == j)
                sta[pos[j]] = 0;

            pos[j] += clock[j];
            if (pos[j] == L) clock[j] = -1;
            else if (pos[j] == 0) clock[j] = 1;

            other = sta[pos[j]];
            if(other > 0)
            {
                if (other > j) 
                    sta[pos[j]] = j;
                else
                {
                    clock[j] = -clock[j];
                    clock[other] = -clock[other];
                }       
            }
            else
            {
                sta[pos[j]] = j;
            }
        }       
    }   
    for (int i = 1; i <= n; ++i)
    {
        cout << pos[i] << " ";
    }
    cout << endl;
}