hust 1427 Funny Funny Game

本文讨论了一个游戏策略问题,玩家需要从一系列独特石头中选择石头进行吃掉,每次吃掉石头可以获得左侧比它小的石头数量作为分数。目标是最大化得分。通过动态规划方法解决了这一问题,并提供了求解数学期望的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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\n",++j , f[n]) ;
    }
}

 

转载于:https://www.cnblogs.com/20120125llcai/p/3355971.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值