zoukankan      html  css  js  c++  java
  • 端点星2020.12.2联赛

    T1

    Solution

    我们对于这 (n) 个数来进行讨论

    首先, 一共有 (A_n^n)中排列, 那么分母我们就确定了

    我们设 (max_1) 是最大的数, (max_2) 是第二大的数, (max_3) 是第三大的数... (max_n)是第n大的数

    1. 对于 (max_1) 它贡献不管如何排列都为0
    2. 对于 (max_2) 它的贡献是 (max_1)(max_2) 前面的排列的个数 (dfrac{A_n^n}{A_2^2})
    3. 对于 (max_3) 它的贡献是 (max_2)(max_3) 前面的排列的个数 (dfrac{A_n^n}{A_2^2}) + (max_1)(max_3) 前面的排列的个数 (dfrac{A_n^n}{A_2^2})
    4. 对于 (max_4) 它的贡献是 (max_3)(max_4) 前面的排列的个数 (dfrac{A_n^n}{A_2^2}) + (max_2)(max_4) 前面的排列的个数 (dfrac{A_n^n}{A_2^2}) + (max_1)(max_4) 前面的排列的个数 (dfrac{A_n^n}{A_2^2})
      .
      .
      .
      n. 对于 (max_n) 它的贡献是 (max_{n - 1})(max_n) 前面的排列的个数 (dfrac{A_n^n}{A_2^2}) + (max_{n - 2})(max_n) 前面的排列的个数 (dfrac{A_n^n}{A_2^2}) + ... + (max_1)(max_n) 前面的排列的个数 (dfrac{A_n^n}{A_2^2}) 就是 (dfrac{A_n^n imes (n - 1)}{A_2^2})

    以此类推, 那么最终答案就是 : 所有的贡献除以总共的排列数:

    (ans = dfrac{dfrac{A_n^n}{A_2^2} + dfrac{A_n^n imes 2}{A_2^2} + dfrac{A_n^n imes 3}{A_2^2} + ... + dfrac{A_n^n imes (n - 1)}{A_2^2}}{A_n^n})

    (Rightarrow ans = dfrac{1}{A_2^2} + dfrac{2}{A_2^2} + dfrac{3}{A_2^2} + ... + dfrac{(n - 1)}{A_2^2})

    (Rightarrow ans = dfrac{1}{2} + dfrac{2}{2} + dfrac{3}{2} + ... + dfrac{(n - 1)}{2})

    同时, 注意相同的数: 相同的数的贡献取决于相同的第一的 (max)

    即, 贡献仅取决于大于他的数

    Code :

    /**
    *  Author: Aliemo
    *  Data: 
    *  Problem: 
    *  Time: O()
    */
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    
    #define ll long long
    #define rr register
    
    #define inf 1e9
    #define MAXN 100010
    
    using namespace std;
    
    inline int read() {
      int s = 0, f = 0;
      char ch = getchar();
      while (!isdigit(ch)) f |= ch == '-', ch = getchar();
      while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
      return f ? -s : s;
    }
    
    void print(int x) {
      if (x < 0) putchar('-'), x = -x;
      if (x > 9) print(x / 10);
      putchar(x % 10 + 48);
    }
    
    int T, n;
    
    int a[MAXN];
    
    double ans[MAXN];
    
    inline bool cmp(int a, int b) {return a > b;}
    
    signed main() {
      // freopen("calculation.in", "r", stdin);
      // freopen("calculation.out", "w", stdout);
      T = read();
      while (T--) {
        n = read();
        double res = 0, lazy = 0;
        for (rr int i = 1; i <= n; i++) a[i] = read();
        for (rr int i = 2; i <= n; i++) ans[i] = ans[i - 1] + 0.5;
        sort(a + 1, a + 1 + n, cmp);
        for (rr int i = 2; i <= n; i++) {
          if (a[i] != a[i + 1]) res += ans[i], lazy = ans[i];
          else res += lazy;
        }
        if (res == (double)((int)(res))) printf("%d", (int)(res));
        else printf("%.2f
    ", res);
      }
    }
    
  • 相关阅读:
    IdHTTP + RegExpr
    Delphi多线程编程之五不同类线程读写全局变量阻塞和锁定
    服务器开发
    Delphi多线程编程之四 线程安全和VCL
    接口测试方式
    LR11开始录制时打不开浏览器
    接口测试基础
    ospf应用简单
    OSPF协议原理及配置4邻接关系的建立和LSDB同步
    windows7安装远程服务器AD域管理工具
  • 原文地址:https://www.cnblogs.com/lieberdq/p/14076265.html
Copyright © 2011-2022 走看看