您的位置:首页 > 其它

Gym - 100814A Arcade Game

2017-07-28 10:48 387 查看
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<cstrin
4000
g>
#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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM题解