본문 바로가기

problem solving/Problem Solving

Crazy tea party


http://acm.pku.edu.cn/JudgeOnline/problem?id=1455

Description

n participants of << crazy tea party >> sit around the table. Each minute one pair of neighbors can change their places. Find the minimum time (in minutes) required for all participants to sit in reverse order (so that left neighbors would become right, and right - left).

Input

The first line is the amount of tests. Each next line contains one integer n (1 <= n <= 32767) - the amount of crazy tea participants.

Output

For each number n of participants to crazy tea party print on the standard output, on a separate line, the minimum time required for all participants to sit in reverse order.


Solving

원탁에 사람들이 있다. 서로 이웃한 사람들 끼리 자리를 바꾸어 원래 앉았던 순서와 반대가 되게 하려 한다. 최소한 몇 번 자리를 옮겨야 하는가?

원탁이 아니라면 이 문제는 교환정렬을 했을 때 교환의 횟수를 구하는 것과 같다. 하지만 원탁이기 때문에 좀 더 적은 횟수로 순서를 반대로 만들 수 있다.

n개의 원소의 순서를 뒤집을 때 필요한 교환의 수는 1~(n-1)까지의 합과 같다. 원탁의 경우에는 n을 반으로 나눠 왼쪽과 오른쪽을 각각 뒤집으면 전체적으로도 순서가 반대가 된다.

'problem solving > Problem Solving' 카테고리의 다른 글

Palindrome Numbers  (0) 2008.10.07
Sum of Factorials  (0) 2008.10.07
Prime Path  (0) 2008.10.07
Ugly Number  (0) 2008.10.06
Subsequence  (0) 2008.10.02