zoukankan      html  css  js  c++  java
  • poj 1455

    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

    3
    4
    5
    6

    Sample Output

    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即可;
    处理一下就得到下面公式
    #include<stdio.h>
    
    int main()
    {
    int n,m;
    scanf("%d",&n);
    while(n--)
    {
    scanf("%d",&m);
    printf("%d
    ",m/2*(m/2-1)/2+(m+1)/2*((m+1)/2-1)/2);
    
    }
    return 0;
    }
  • 相关阅读:
    面试题总结(vue面试题)
    面试题总结(css面试题)
    设置div居中显示
    关于js中iframe 中 location.href的用法
    js判断是否在iframe中
    npm git 常用命令行 记录
    mongDB数据库 小白学习
    EJS 入门学习
    bower 基础认识
    gulp 粗粗学习 记录下
  • 原文地址:https://www.cnblogs.com/jin-nuo/p/5511395.html
Copyright © 2011-2022 走看看