Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <chrono>
  4. double pmax = 0.18;
  5. using namespace std;
  6. random_device rd;
  7. mt19937 mt(rd());
  8. random_device rand1, rand2;
  9. mt19937 mt1(rand1()), mt2(rand2());
  10. uniform_real_distribution<double> dist(0.0, 1.0);
  11. uniform_int_distribution<int> dist1(0, 5);
  12. uniform_real_distribution<double> dist2(0.0, pmax);
  13.  
  14. void odwracanie() {
  15.     int tab[6], counter = 0, amount = 200000, temp1, amountHit = 0;
  16.     double tabProc[6] = { 0.16, 0.17, 0.18, 0.17, 0.165, 0.155 };
  17.  
  18.     for (int i = 0; i < 6; i++)
  19.         tab[i] = 0;
  20.  
  21.     while (true) {
  22.         temp1 = dist1(mt1);
  23.  
  24.         if (dist2(mt2) <= tabProc[temp1]) {
  25.             tab[temp1]++;
  26.             amountHit++;
  27.         }
  28.  
  29.         if (amountHit > amount)
  30.             break;
  31.     }
  32.  
  33.     for (int i = 0; i < 6; i++)
  34.         cout << (double)tab[i] / (double)amount * (double)100 << " ";
  35. }
  36.  
  37. void eliminacja() {
  38.     int tab[4], size = 4, amount = 200000;
  39.     double random;
  40.     for (int i = 0; i < size; i++) {
  41.         tab[i] = 0;
  42.     }
  43.  
  44.     for (int i = 0; i < 200000; i++) {
  45.         random = dist(mt);
  46.         if (random < 0.8)
  47.             tab[0]++;
  48.         else if (random < 0.9)
  49.             tab[1]++;
  50.         else if (random < 0.96)
  51.             tab[2]++;
  52.         else
  53.             tab[3]++;
  54.     }
  55.  
  56.  
  57.  
  58.     for (int i = 0; i < size; i++) {
  59.         cout << (double)tab[i] / (double)amount * (double)100 << " ";
  60.     }
  61. }
  62. int main() {
  63.     std::chrono::duration<double> czas;
  64.     auto poczatek = std::chrono::high_resolution_clock::now();
  65.     odwracanie();
  66.     auto koniec = std::chrono::high_resolution_clock::now();
  67.     czas = koniec - poczatek;
  68.     std::cout << std::fixed << "czas odwracania:  " << czas.count() << " s\n";
  69.     poczatek = std::chrono::high_resolution_clock::now();
  70.     eliminacja();
  71.     koniec = std::chrono::high_resolution_clock::now();
  72.     czas = koniec - poczatek;
  73.     std::cout << std::fixed << "czas czas eliminacji:  " << czas.count() << " s\n";
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement