前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >poj 1455

poj 1455

作者头像
瑾诺学长
发布2018-09-21 16:30:06
3800
发布2018-09-21 16:30:06
举报
文章被收录于专栏:专注研发

Description

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

代码语言:javascript
复制
3
4
5
6

Sample Output

代码语言:javascript
复制
2
4
6
参考别人的
把1 2 3 4 5换成5 4 3 2 1或 3 2 1 5 4都满足题意;
即把其当作一个环处理,所以进行分段】
当n为偶数  每份n/2个  花费时间(n/2)*(n/2-1)/2
当n为奇数,一份n/2,另一份n+1/2,代入n*(n-1)/2即可;
处理一下就得到下面公式
代码语言:javascript
复制
#include<stdio.h>

int main()
{
int n,m;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
printf("%d\n",m/2*(m/2-1)/2+(m+1)/2*((m+1)/2-1)/2);

}
return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-05-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档