오늘은 codeforces Div 3 후기겸 풀이를 올려보려고 한다.

사실 코포 대회는 주로 저녁 11시 35분에서 새벽 1시 35분까지 열리기 때문에(러시아에서 열리는 대회라 그렇다) 12시에 칼같이 자는 나에게는 적합한 대회가 아니다. (...)

그래도 재미삼아 A번이라도 풀기 위해 대회에 참가했다.(그리고 목표에 충실하게 A번만 풀고 빤스런했다)

그럼 본격적으로 풀이와 후기를 써본다.

A. Special Permutation

Problem Statement

You are given one integer n (n>1).

Recall that a permutation of length nn is an array consisting of nn distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation of length 5, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

Your task is to find a permutation p of length n that there is no index i (1in) such that pi=i(so, for all i from 1 to n the condition pii should be satisfied).

You have to answer t independent test cases.

If there are several answers, you can print any. It can be proven that the answer exists for each n>1.

 

Input

The first line of the input contains one integer t (1t100) — the number of test cases. Then t test cases follow.

The only line of the test case contains one integer n (2n100) — the length of the permutation you have to find.

 

Output

For each test case, print n distinct integers p1,p2,,pn — a permutation that there is no index i (1i≤n) such that pi=i (so, for all i from 1 to n the condition pii should be satisfied).

 

If there are several answers, you can print any. It can be proven that the answer exists for each n>1.

 

풀이

쉽게 생각하면 쉽고, 어렵게 생각하면 어려운 문제이다.

문제를 번역하면 이렇다.

'n이 주어질 때 n의 순열 p1,p2,,pn pii 인 순열을 아무거나 출력하세요'

이를 더 간단하게 바꾸면 다음과 같다.

'n이 주어질 때 n의 교란순열중 하나를 출력하세요'

따라서 n의 순열 중 기본적인 것인 1, 2, ..., n 을 한칸씩 밀려쓴 순열을 출력하면 정답이 된다.

#include <stdio.h>
int main()
{
    int t,i;
    scanf("%d\n",&t);
    while(t--)
    {
        int a;
        scanf("%d",&a);
        for(i=2;i<=a;i++)
        {
            printf("%d ",i);
        }
        printf("1 ");
    }
    return 0;
}

[00:09 Wrong Answer on test 2]

[00:09 Wrong Answer on test 1]

[00:10 Accepted]

a가 홀수일 때와 짝수일 때를 굳이 나눠서 생각하다가 1틀을 하고, 마지막에 띄어쓰기가 없어서 또 1틀을 했다.

이런데서 실수하지 말자... ㅠㅠ

 

B번은 간단한 구현 문제로 보인다. 업솔빙 예정.

+ Recent posts