Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. inline double fact(double n) {
  6.     if (!n) return 1;
  7.     for (int i = n - 1; i > 0; --i)
  8.         n *= i;
  9.     return n;
  10. }
  11.  
  12. std::vector<double> playerChance ({2/double(3), 1/double(2), 1/double(3), 1/double(4)});
  13. std::vector<double> enemyChance ({1/double(3), 1/double(2), 2/double(3), 3/double(4)});
  14.  
  15. int main() {
  16.     double total = 1;
  17.     for (int i = 0; i < 4; ++i) {
  18.         double base = pow(playerChance[i], 10);
  19.         double runningCount = 0;
  20.         double runChance = 0;
  21.         for (int j = 0; j < 10; ++j) {
  22.             double chances = fact(10+j) / (fact(10) * fact(j));
  23.             chances -= runningCount;
  24.             runningCount += chances;
  25.             double result = base * (pow(enemyChance[i], j));
  26.             runChance += result*chances;   
  27.         }
  28.         total *= runChance;
  29.         std::cout << std::fixed << '\n' << runChance << '\n' << total << '\n';
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement