poj 1455

简介: Description n participants of > sit around the table. Each minute one pair of neighbors can change their places.

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.

Sample Input

3
4
5
6

Sample Output

2
4
6
参考别人的
把1 2 3 4 5换成5 4 3 2 1或 3 2 1 5 4都满足题意;
即把其当作一个环处理,所以进行分段】
当n为偶数 每份n/2个 花费时间(n/2)*(n/2-1)/2
当n为奇数,一份n/2,另一份n+1/2,代入n*(n-1)/2即可;
处理一下就得到下面公式
#include<stdio.h>

int main()
{
int n,m;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
printf("%d\n",m/2*(m/2-1)/2+(m+1)/2*((m+1)/2-1)/2);

}
return 0;
}

 

相关文章
|
6月前
poj-1611-The Suspects
poj-1611-The Suspects
28 0
|
6月前
Hopscotch(POJ-3050)
Hopscotch(POJ-3050)
POJ 2487 Stamps
POJ 2487 Stamps
104 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
843 0
POJ 1067 取石子游戏
取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 40917   Accepted: 13826 Description 有两堆石子,数量任意,可以不同。
1112 0
|
测试技术
POJ 1001
此题用最朴素的思路实现即可,需模拟加法器,乘法器,最烦人的地方是特殊情形,如末位是小数点(12.^2=144,取小数点),整数末位是0(100^2=10000),0次幂,测试用例可能超出题目中说的范围,可能包含0次幂(100.0^0=0, 0.10^1=0.1)。
753 0
poj 3664
http://poj.org/problem?id=3664 进行两轮选举,第一轮选前n进入第二轮,第二轮选最高   #include #include using namespace std; struct vote { int a,b; int c; ...
735 0
POJ 2027 No Brainer
Problem Description Zombies love to eat brains. Yum. Input The first line contains a single integer n indicating the number of data sets.
868 0