poj 1455 Crazy tea party(数学)

来源:互联网 发布:免费的电子书软件 编辑:程序博客网 时间:2024/06/16 18:52
Crazy tea party
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 7318 Accepted: 4973

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

3456

Sample Output

24

6

solution:

设a = n / 2, b = n - a 则答案为a*(a - 1) / 2 + b*(b - 1) / 2)

#include<cstdio>using namespace std;int main(){int  t,n;scanf("%d", &t);while (t--){scanf("%d", &n);int a = n / 2, b = n - a;printf("%d\n", a*(a - 1) / 2 + b*(b - 1) / 2);}return 0;}


0 1
原创粉丝点击