시도 횟수: 1회

해결한 시간: 00:09

문제 번역(GPT)

핵심 아이디어

<aside> 💡

$p_n = n,\ p_{n-1} = 1$

$p_{n-2} = n-1,\ p_{n-3}=2$

와 같은 방식으로 계속 구성하면 됨.

</aside>

코드

#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
typedef long long ll;

int n;
int ans[101];

void solve()
{
    cin >> n;
    int cur = n;
    memset(ans, 0, sizeof(ans));

    int idx = cur;
    while(idx>0){
        ans[idx] = cur;
        idx -= 2;
        cur--;
    }
    for(int i = 1; i<=n; i++){
        if(ans[i]) continue;
        ans[i] = cur--;
    }

    for(int i = 1; i<=n; i++){
        cout << ans[i] <<" ";
    }
    cout << "\\n";
}

signed main()
{
    FASTIO;
    int _tc; cin >> _tc;
    while (_tc--) solve();
    return 0;
}

복기

A번 치고 어려웠는데 운 좋게 빠르게 발견함.