Crazy Tea Party

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


提议概述:
              n个人按编号围着桌子坐成一圈,编号由1-n,每次只能交换相邻座位的人的位置,问多少次可以将所有人的左右两人互换,即左边的人到他的右边,右边的人到他的左边。

解题思路:
              如果n个人按编号站成一排,则此题就是一个冒泡排序,如:1,2,3,4,5变为5,4,3,2,1即可,(n/2)*(n/2-1)/2;
              如果n个人围桌坐成一圈,则需要将人分为两组,这两组各自形成一个列,用冒泡排序分别处理两组人即可,最后将结果相加。若n为偶数,则为(n/2)*(n/2-1);若为奇         数,则为(n/2)*(n/2-1)/2+(n/2+1)*(n/2)/2;

源代码:

  1. #include<iostream> 
  2. using namespace std;  
  3.   
  4. int main()  
  5. {  
  6.     int T,N,M;  
  7.     cin>>T;  
  8.     while(T--)  
  9.     {  
  10.         cin>>T;    
  11.         if(N%2==0)  
  12.         {  
  13.             M=(N/2)*(N/2-1);  
  14.         }  
  15.         else  
  16.         {  
  17.             M=(N/2)*(N/2-1)/2+(N/2+1)*(N/2)/2;  
  18.         }  
  19.         cout<<M<<endl;  
  20.     }  
  21.     return 0;
  22. }  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值