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. ocp 1Z0-051 71-105题解析

    71. Which arithmeticoperations can be performed on a column by using a SQL function that is builtint ...

  2. java 字符串String操作工具类

    /** * StrKit. */ public class StrKit { /** * 首字母变小写 */ public static String firstCharToLowerCase(Str ...

  3. JMS开发(一):基础理论认知

    JMS全称是Java Message Service.其是JavaEE技术规范中的一个重要组成部分,是一种企业消息处理的规范.它的作用就像一个智能交换机,它负责路由分布式应用中各个组件所发出的消息. ...

  4. c++出错记录

    错误1如下:  vector<vector<int>> m_vc;  error: '&' cannot appear in a constant-expression ...

  5. nm命令详解

    nm在linux中列出目标文件的符号清单,常用来查看动态链接库中的函数 nm支持的选项如下 -a   按照man手册,仅列出调试信息,实际上却是调试信息+正常信息 -A   增加一列显示目标文件,没有 ...

  6. 关于Token

    Token Token,即计算机术语:令牌 令牌是一种能够控制站点占有媒体的特殊帧,以区别数据帧及其他控制帧.token其实说的更通俗点可以叫暗号,在一些数据传输之前,要先进行暗号的核对,不同的暗号被 ...

  7. Struts2内建校验器(基于校验框架的文件校验)

    位于xwork-2.0.4.jar压缩包中( com.opensymphony.xwork2.validator.validators)有个文件default.xml ,该文件中定义了Struts2框 ...

  8. ubuntu 15.04开放mysql远程连接

    首先查看端口是否打开 netstat -an|grep 3306 此图为开启3306端口的截图,之前显示为. . . 127.0.0.1:3306 . . . 打开mysql配置文件vi /etc/m ...

  9. Linux rsync 同步实践

    目录[-] 1. rsync 同步的大致思路 2. rsync的安装 3. rsync的配置 4. rsync的基本操作 服务器端启动 注2. 实时同步 注3. rsync通过linux防火墙 公司网 ...

  10. strcpy_s与strcpy的比較

    strcpy_s和strcpy()函数的功能差点儿是一样的.strcpy函数,就象gets函数一样,它没有方法来保证有效的缓冲区尺寸,所以它仅仅能假定缓冲足够大来容纳要拷贝的字符串.在程序执行时,这将 ...