fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define initial first
  7. #define added second
  8.  
  9. #define EGRY \
  10.   ios_base::sync_with_stdio(false); \
  11.   cin.tie(NULL);
  12.  
  13. const int MAX = 100 + 50;
  14. const int MOD = 998244353;
  15. const int OO = INT_MAX;
  16.  
  17. const double EPS = (double)1e-9;
  18.  
  19. void solve()
  20. {
  21. string n, org;
  22. cin >> n;
  23. vector<string> p;
  24.  
  25. org = n;
  26. sort(n.begin(), n.end());
  27.  
  28. do
  29. {
  30. p.push_back(n);
  31. } while (next_permutation(n.begin(), n.end()));
  32.  
  33. double fact = (int)p.size();
  34.  
  35. if (org == p[fact - 1])
  36. {
  37. cout << fixed << setprecision(9) << 0.0 << endl;
  38. return;
  39. }
  40.  
  41. double res = 1.0 / fact;
  42.  
  43. if (org == p[fact - 2])
  44. {
  45. cout << fixed << setprecision(9) << res << endl;
  46. return;
  47. }
  48.  
  49. for (int i = fact - 3; i >= 0; i--)
  50. {
  51. res = res + (1.0 / fact) * res;
  52. if (p[i] == org)
  53. {
  54. cout << fixed << setprecision(9) << res << endl;
  55. }
  56. }
  57. }
  58.  
  59. int main()
  60. {
  61. EGRY int t = 1;
  62. cin >> t;
  63.  
  64. while (t--)
  65. {
  66. solve();
  67. }
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
0.000000000