• hust 1427 Funny Funny Game


    HUST - 1427

    Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu

    []   [Go Back]   [Status]  

    Description

    Super Hanhan(SH) loves playing all kinds of little games very much. Today rocket323 recommends a new game to SH.

    The game’s name is “Eating stones”, and it’s played like this: in a single round, the game system will randomly generate a sequence of N numbers(all of these N numbers are unique) representing the size of stones, and place them from left to right in a single line. Each time the player can choose one stone to eat, and then get a score of P points, which equal to number of remaining stones which are smaller than the chosen stone and to the left of the chosen stone.

    SH wants to maximize the score he can get, however, he can’t figure out the best strategy to reach the goal. So he asks you(a talented programmer) for help.

    Please help the poor SH find out the best strategy and tell him the expected scores he can get under this strategy.

    Input

    There are multiple cases.

    The first line is an integer T representing the number of test cases.

    The following T lines each line representing a test case. For each case there is exactly one line containing a single number N, representing the number of stones in the game. (1 <= N <= 1000000)

    Output

    For each test case, output a line containing the answer in the following format:

    Case #K: X

    K is the case number starting from 1, and X must be printed as a real number with two-digit precision, and the last decimal digit must be rounded.

    Sample Input

    2
    1
    3

    Sample Output

    Case #1: 0.00
    Case #2: 1.50
    //题目的意思是从 n 块石头开始 每次你可以吃一块 总分加上这个是左边有多少个石头
    //知道没有石头为止.....
    //面对 x 块石头我们可以把它分割个 x 个 情况 ,dp[x] 表示该情况下的方法总数
    //假如我们取第 i 块石头 那么 他左边就有i-1 块 取了以后就转化为x-1 块石头的问题
    //改方案对dp[x] 有 dp[x-1]+i*((x-1)!) 贡献 ,把他们累加 
    // 有 dp[x] = dp[x-1]*x+((x-1)!)((x-1)*x)/2 
    // f[x] 表示其数学期望 有 f[x] = dp[x]/(x!) -> dp[x] = (x!)*f[x] ;
    //带入上面 有 f[x] = f[x-1]+(x-1)/2 ;
    // yong c 写的 代码要改到最短==。 
    #include<stdio.h>
    double f[1000010] ;
    int main()
    {
        int i , n , j = 0 ;
        f[1] = 0 ;
        for( i = 2 ; i <= 1000000 ;i++ )
            f[i] = f[i-1]+(i-1)*0.5 ;
        scanf("%d",&i) ;
        while(i--)
        {
             scanf("%d",&n) ;
             printf("Case #%d: %.2lf
    ",++j , f[n]) ;
        }
    }
    
  • 相关阅读:
    echarts地图引入json或者js
    SpringMVC开启定时任务
    MYSQL基础
    js获取表格单元格中的元素
    转载:【Java基础】InputStream 、 InputStreamReader和BufferedReader
    转载:普通索引和唯一索引的区别、性能差异,以及其他索引简介
    String与StringBuffer之间的转换
    回调
    Java中的类加载器
    ecshop ajax 的调用原理
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3355971.html
Copyright © 2020-2023  润新知