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. red5下nginx安装配置

    http://zfl110.iteye.com/blog/1155149 原址:http://lqw.iteye.com/blog/652763 安装Nginx 1.首先安装pcre-8.02.tar ...

  2. thymeleaf中的条件判断用法

    一.简单的条件:“if”和“unless” th:if用法实例: <table> <tr> <th>NAME</th> <th>PRICE& ...

  3. string中c_str()、data()、copy(p,n)函数的用法

    标准库的string类提供了3个成员函数来从一个string得到c类型的字符数组:c_str().data().copy(p,n). 1. c_str():生成一个const char*指针,指向以空 ...

  4. JMS开发(二):深入PTP,Pub-Sub两种模式

    1.PTP模型 PTP(Point-to-Point)模型是基于队列(Queue)的,对于PTP消息模型而言,它的消息目的是一个消息队列(Queue),消息生产者每次发送消息总是把消息送入消息队列中, ...

  5. 如何将std::string转int,double? (C/C++) (C) (template)

    http://www.cnblogs.com/oomusou/archive/2008/08/01/525647.html http://blog.sina.com.cn/s/blog_a843a88 ...

  6. zendstudio 10下载汉化

      1.文件和汉化文件 ZendStudio官方下载地址:http://www.geekso.com/component/zendstudio-downloads/ 百度云地址: 10.0.0.msi ...

  7. andriod开发,简单的封装网络请求并监听返回.

    一.为什么封装 因为android 4.0 以后的发送网络请求必须要放到异步线程中,而异步线程必须跟handle合作才能更新主线程中的UI,所以建议用一个类继承handler来异步处理网络请求. 二. ...

  8. Displaying Alerts with UIAlertView

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"You've ...

  9. Codeforces Round #327 (Div. 2) B. Rebranding 水题

    B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...

  10. 套题 Codeforces Round #277 (Div. 2)

    A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...