UVALive 2756 Crazy tea party

探讨一组参与者如何通过相邻交换达到初始状态的反转,提供了一种计算最少交换次数的方法。

Question:
Description
Download as PDF
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
题意大意:许多人坐在一起,每次交换只能与邻近的交换,问要交换多少次才能使相邻的人互换,(即使左边邻居变为右边邻居)
这道题我不知道怎么做,在别人讲了以后还是不知道代码怎么来的。
(http://acm.hust.edu.cn/vjudge/contest/121559#problem/M)

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n,t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n;
        cout<<n/2*((n-1)/2)<<endl;
    }
    return 0;
}

代码虽短,但却并不知道怎么来的

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值