Dsecription

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/2)号往左交换,(n/2)~n号往右交换。比如:
n = 6时:
  1 2 3 | 4 5 6
  1 3 2 | 5 4 6
  3 1 2 | 5 6 4 (以上3,4分别移至两侧)
  3 2 1 | 6 5 4 (2,5移至两侧)
  
  以上完成逆序变换; n = 7时:
  1 2 3 4 | 5 6 7
    ...
  4 1 2 3 | 6 7 5
    ...
  4 3 1 2 | 7 6 5
  4 3 2 1 | 7 6 5
这样每个数需要交换的次数分别为 (偶)0 1,2,...,(n/2)-1, (n/2)-1,...,2,1,0
                (奇)0 1,2,...,(n/2), (n/2)-1,...,2,1,0
求和即可。

【代码】:代码可能略繁琐。自己可以简化一下。
 #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int T; scanf("%d", &T);
while(T--)
{
int n, ans = ; scanf("%d", &n);
if(n%)
{
int num = n/;
ans = (+(num-)) * (num-);
ans += num;
}
else
{
int num = n/;
ans = (+(num-)) * (num-);
}
cout << ans << endl;
}
return ;
}

【置换,推理】UVa 1315 - Creaz tea party的更多相关文章

  1. 【uva 10294】 Arif in Dhaka (First Love Part 2) (置换,burnside引理|polya定理)

    题目来源:UVa 10294 Arif in Dhaka (First Love Part 2) 题意:n颗珠子t种颜色 求有多少种项链和手镯 项链不可以翻转 手镯可以翻转 [分析] 要开始学置换了. ...

  2. UVA 11246 - K-Multiple Free set(数论推理)

    UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合.求一个子集合.使得元素个数最多,而且不存在有两个元素x1 * k = x2,求出最多的元素个数是 ...

  3. UVA 10294 项链与手镯 (置换)

    Burnside引理:对于一个置换\(f\), 若一个着色方案\(s\)经过置换后不变,称\(s\)为\(f\)的不动点.将\(f\)的不动点数目记为\(C(f)\), 则可以证明等价类数目为\(C( ...

  4. UVa 11330 (置换 循环的分解) Andy's Shoes

    和UVa11077的分析很类似. 我们固定左脚的鞋子不动,然后将右脚的鞋子看做一个置换分解. 对于一个长度为l的循环节,要交换到正确位置至少要交换l-1次. #include <cstdio&g ...

  5. UVa 11077 Find the Permutations(置换+递推)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35431 [思路] 置换+递推 将一个排列看作一个置换,分解为k个循 ...

  6. uva 1561 - Cycle Game(推理)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=4336" style=""& ...

  7. uva 11077 置换

    /** 给定一个置换,看能不能存在一个置换A^2 = B 思路; 循环节长度为偶数n的置换只能由循环节长度为长度2*n 的置换A*A 而变得.所以只需求出循环节,看循环节长度为偶数的个数是否为偶数个即 ...

  8. UVA 1364 - Knights of the Round Table (获得双连接组件 + 二部图推理染色)

    尤其是不要谈了些什么,我想A这个问题! FML啊.....! 题意来自 kuangbin: 亚瑟王要在圆桌上召开骑士会议.为了不引发骑士之间的冲突. 而且可以让会议的议题有令人惬意的结果,每次开会前都 ...

  9. 【UVA 11077】 Find the Permutations (置换+第一类斯特林数)

    Find the Permutations Sorting is one of the most used operations in real life, where Computer Scienc ...

随机推荐

  1. (转)定制iOS 7中的导航栏和状态栏

    近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这也就意味着导航栏 ...

  2. URAL 2045 Richness of words (回文子串,贪心)

    Richness of words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/J Description For each ...

  3. jps用法

    jps(Java Virtual Machine Process Status Tool)是JDK 1.5提供的一个显示当前所有java进程pid的命令,简单实用,非常适合在linux/unix平台上 ...

  4. C C++实现创建目录

    下面代码是C.C++可以使用的创建目录的函数及头文件,这是引用的opencv,haartraining中的一种方式. #include <direct.h> //不同系统可能不一样,这是在 ...

  5. HDU 3665 Seaside (最短路,Floyd)

    题意:给定一个图,你家在0,让你找出到沿海的最短路径. 析:由于这个题最多才10个点,那么就可以用Floyd算法,然后再搜一下哪一个是最短的. 代码如下: #pragma comment(linker ...

  6. 关于spring管理hibernate事物

    下面这篇文章对我帮助很大.http://blog.csdn.net/jianxin1009/article/details/9202907

  7. Android游戏之平台接入的一点记录

    最近手头有需要接入多个渠道的工作,我负责的是Android方面的接入,一般来说,渠道是非常多的,每一个渠道调用的接口都不一致,如果每一个渠道都要自己去弄回非常的耗时,所以网上会有一些接入的中间件提供商 ...

  8. TCP四种定时器--学习笔记

    TCP使用四种定时器: 重传定时器(Retransmission Timer).坚持定时器(Persistent Timer).保活定时器(Keeplive Timer).时间等待定时器(Time_W ...

  9. Ping批量函数

    function pingm ($file){ $ips = gc $file foreach ($ip in $ips) { $cmdline +="ping " + $ip + ...

  10. .net自动生成版本号

    在 AssemblyInfo.cs 文件中 修改 一下属性 [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFi ...