• Road To The 3rd Building 未解决


    https://vjudge.net/contest/387998#problem/A

    Because of the thriller adventure game The 3rd Building, there are fewer and fewer students who would like to go to the 3rd Building. So few students are working in the studio in the 3rd Building. Students are even more reluctant to go to the 3rd Building for experiments, which are also annoying.

    Kanade takes responsibility to improve this status. She thinks it a good idea to decorate the ginkgo trees along the road to the 3rd Building, making them cute. There are $n$ ginkgo trees that are planted along the road, numbered with $1ldots n$. Each tree has a cute value. The cute value of tree $i$ is $s_i$.

    Kanade defines a plan as an ordered pair $(i,j)$, here $1le ile jle n$. It means a student will appear at the position of the tree $i$ magically, walk along the road, and finally stop walking at the position of the tree $j$. The cute level of a plan is the average of the cute value of the trees visited. Formally, the cute level of plan $(i,j)$ is $frac{1}{j-i+1}sum_{k=i}^j s_k$.

    Kanade wants to know the mathematical expectation of the cute level if a student will take a plan among all these plans in a uniformly random way. But she is busy with learning Computer Networking, would you help her?

    InputThe first line of the input contains an integer $T$ — the number of testcases. You should process these testcases independently.

    The first line of each testcase contains an integer $n$ — the number of ginkgo trees.

    The second line of each testcase contains $n$ integers $s_i$ — the cute value of each ginkgo tree, space-separated.

    $1le Tle 20,1le nle 2 imes 10^5,1le s_ile 10^9$

    It is guaranteed that $sum nle 10^6$.OutputFor each testcase, output the answer in the fraction form modulo $10^9+7$ in one line. That is, if the answer is $frac{P}{Q}$, you should output $Pcdot Q^{-1}mod (10^9+7)$, where $Q^{-1}$ denotes the multiplicative inverse of $Q$ modulo $10^9+7$.Sample Input

    3
    3
    1 3 2
    6
    1 1 4 5 1 4
    9
    7325 516 56940 120670 16272 15007 337527 333184 742294

    Sample Output

    83333336
    188888893
    303405448
    

     题意:

      给n个数的序列,现在任意选择一个区间定义一个平均值

      

      求出这个平均值的期望

    思路:

      参考:https://blog.csdn.net/fztsilly/article/details/107847396

      找规律

      k = 1项和k = n项分子相同

         s[n1] ,

      (s[n1]+s[n])/ 2 ,

        ...,

      (s[1] + s[2]+...+s[n])/n

       每次对分母取逆元

      (有奇数项,另外加上最中间的数?

    未通过

     

      

  • 相关阅读:
    Thinkph5——模型软删除
    ThinkPHP5——URL参数带中文,报"模块不存在"
    ThinkPHP5多模板配置二级域名
    使用Composer安装阿里云短信失败
    GIT快速入门
    Python全栈之路系列----之-----面向对象4(接口与抽象,多继承与多态)
    Python全栈之路系列----之-----面向对象3(继承与派生)
    Python全栈之路系列----之-----面向对象1(初识)
    Python全栈之路系列----之-----异常处理
    Python全栈之路系列----之-----内置函数和匿名函数lamdba
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13476005.html
Copyright © 2020-2023  润新知