Advertisement
asaelr

bottles

Apr 28th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdint>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <random>
  6.  
  7. using namespace std;
  8. const int N = 1000;
  9. const int S = 58;
  10. const double p = 1-sqrt(0.5);
  11.  
  12. uint64_t bottles[N];
  13. uint64_t deaths[N*(N-1)/2];
  14. bool check() {
  15.     int k=0;
  16.     for (int i=1;i<N;i++) for (int j=0;j<i;j++) deaths[k++]=bottles[i]|bottles[j];
  17.     sort(deaths,deaths+k);
  18.     return unique(deaths,deaths+k)==deaths+k;
  19. }
  20.  
  21. void draw() {
  22.     static random_device rd;
  23.     static mt19937 gen(rd());
  24.     bernoulli_distribution d(p);
  25.     for (int n=0;n<N;n++) {
  26.         bottles[n]=0;
  27.         for (int s=0;s<S;s++) {
  28.             if (d(gen)) bottles[n] |= (uint64_t(1)<<s);
  29.         }
  30.     }
  31. }
  32.  
  33. void print() {
  34.     for (int s=0;s<S;s++) {
  35.         for (int n=0;n<N;n++) cout<<(bottles[n]&(uint64_t(1)<<s)?1:0);
  36.         cout<<endl;
  37.     }
  38. }
  39.  
  40. int main() {
  41.     int t = 0;
  42.     do {
  43.         draw();
  44.         cout<<"try "<<++t<<endl;
  45.     } while (!check());
  46.     print();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement