Gym - 100814A Arcade Game
2017-07-28 10:48
387 查看
Gym - 100814A Arcade Game
题意是在一个游戏中,你会看到一个n,按下按钮,一个球击中n个数。n的每个位数在空中飞,它的数字在任何随机排列中都会以均匀的概率回落。如果生成的新数字小于或等于前一个数字,则游戏结束。否则(如果数字大于前一个数字),你仍然在游戏中,你应该再次点击按钮。如果生成的新数字大于前一个数字,等于最大可能的置换数,则获胜。求获胜的概率。公式:(1+x)n=∑r=0nCrnxr
题意是在一个游戏中,你会看到一个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(); }
相关文章推荐
- Gym - 100814A Arcade Game(全排列)
- Gym 100814A---Arcade Game
- 【递推】【概率】Gym - 100814A - Arcade Game
- Gym 100339A Bike Roads
- Codeforces Gym 100500A Poetry Challenge (博弈论基础题)
- Codeforces Gym 100187D D. Holidays 排列组合
- Gym 100712I Bahosain and Digits(枚举)
- Codeforces Gym 100637B B. Lunch 找规律
- codeforce Gym 100500H ICPC Quest (简单dp)
- Gym 100703M It's complicated 水题
- Gym 100712F - Travelling Salesman
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
- codeforces Gym 100286H Hell on the Markets
- Gym 100379C Fibonacci number’s ratio (the hard version) (特征方程)
- codeforce Gym 100203I I WIN (网络流)
- Gym - 100203J Journeys on the Moscow Underground
- Gym 100650H Two Ends DFS+记忆化搜索
- Codeforces Gym 100733J Summer Wars 线段树,区间更新,区间求最大值,离散化,区间求并
- Gym 100338I TV show (dfs枚举)
- GYM 100685 G【并查集】