zoukankan      html  css  js  c++  java
  • 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]) ;
        }
    }
    
  • 相关阅读:
    openmp 循环并行化循环嵌套内部无法并行
    c++:strcat潜在的错误不报告
    script php / phpfpm /
    webserver waf / WAF 2.0 / ASERVER/1.2.9
    web test LoadRunner FTP / vsftpd / vsftp / WebUploader 0.1.5 / shangchuan
    my ReadTravel_Singapore / singapore / xinjiapo / lvyou / travel
    OS Security var_log_secure / services / port
    EF操作数据库的步骤和一些简单操作语句
    (大快人心,必须转啊)中国体操男队完美逆转卫冕 日本申诉成功获银牌
    [置顶] 【C/C++学习】之一、指针和引用的区别
  • 原文地址:https://www.cnblogs.com/20120125llcai/p/3355971.html
Copyright © 2011-2022 走看看