Gym - 100814A Arcade Game

Gym - 100814A Arcade Game

题意是在一个游戏中,你会看到一个n,按下按钮,一个球击中n个数。n的每个位数在空中飞,它的数字在任何随机排列中都会以均匀的概率回落。如果生成的新数字小于或等于前一个数字,则游戏结束。否则(如果数字大于前一个数字),你仍然在游戏中,你应该再次点击按钮。如果生成的新数字大于前一个数字,等于最大可能的置换数,则获胜。求获胜的概率。公式:(1+x)n=r=0nCrnxr

/*bool next_permutation( iterator start, iterator end);
next_permutation函数的返回值是布尔类型,在STL中还有perv_permutation()函数
next_permutation()函数功能是输出所有比当前排列大的排列,顺序是从小到大。
而prev_permutation()函数功能是输出所有比当前排列小的排列,顺序是从大到小。*/

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include <bitset>
using namespace std;
#define LL long long
#define PI 3.141592654
#define eps 1e-6
#define inf 1e9+7
const int maxn = 1e3 + 7;
int t, n, c[20], hh[20];
char str[20];

void solve(){
    scanf("%d", &t);
    hh[1] = 1;
    for(int i = 2; i <= 9; i++)
        hh[i] = hh[i-1]*i;
    while(t--) {
        scanf("%s", str);
        int len = strlen(str), xx = 0, yy = 0;
        for(int i = 0; i < len; i++)
            c[i] = str[i]-'0';
        yy = hh[len];
        while(next_permutation(c, c+len))
            xx++;
        double ans = 0, sum = 1.0;
        printf("%d\n", xx);
        for(int i = 1; i <= xx; i++) {
            ans = (sum/((double)yy));
            sum += ans;
        }
        printf("%.9f\n", ans);
        /*double temp=1.0/yy;
            q=p=temp;
            for(int i=1;i<cnt;i++) {
                q=p+p*temp;
                p=q;
            }
            printf("%.9lf\n",p);
        }*/
    }
}
int main(void){
    solve();
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值