zoukankan      html  css  js  c++  java
  • hdu 1214

    找规律的题目。如果不是圆环形状的话(也就是n个人排成直线),完全调换顺序需要(n-1)*n/2次交换;为环形的时候,可能不需要这么多,因为调换有了两个方向。我们记直线时n个人需要的交换次数为g(n)=(n-1)*n/2,显然g(n)是以n的平方增长的,所以要使总的交换次数尽量少,最佳情况就是将n分成尽量平均的两部分,分别向两个方向交换。

    /*
    * hdu1214/win.cpp
    * Created on: 2011-10-12
    * Author : ben
    */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;

    int main() {
    #ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
    #endif
    int n;
    while (scanf("%d", &n) != EOF) {
    int m, sum, a, b;
    m = n / 2;
    a = (m - 1) * m / 2;
    b = (n - m - 1) * (n - m) / 2;
    sum = a + b;
    printf("%d\n", sum);
    }
    return 0;
    }



  • 相关阅读:
    字符串比较
    LOOP AT SCREEN
    Trunc的日期用法
    【ABAP】SELECT-ENDSELECT尽量不要用
    【转】Abap For all entries in 使用
    01如何创建sequence:
    abap --MOVE-CORRESPONDING
    Abap 常用变量
    StringBuffer的用法
    Spring事务的传播方式
  • 原文地址:https://www.cnblogs.com/moonbay/p/2209419.html
Copyright © 2011-2022 走看看