Advertisement
HasanRasulov

rice.cpp

Dec 27th, 2020
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <array>
  6. #include <iostream>
  7.  
  8. std::vector<int> solution(std::vector<int>& A,int F,int M){
  9.  
  10.     int sum=std::accumulate(A.begin(),A.end(),0);
  11.     int sum_of_missed=M*(A.size()+F)-sum;
  12.  
  13.     constexpr unsigned char pro_length = 7;
  14.     std::array<double,pro_length> pro;
  15.  
  16.     for(int i=1;i<pro_length;i++){
  17.         pro[i] = sum_of_missed > i ? (double)(1.0 / 6.0) : 0.0;
  18.     }
  19.          
  20.     std::default_random_engine generator;
  21.     std::discrete_distribution<int> distribution(pro.begin(),pro.end());
  22.  
  23.     std::vector<int> misseds;
  24.     while(true){
  25.         int sum_of_randoms=0,x;
  26.         for(int i=0;i<F;i++){
  27.             x=distribution(generator);
  28.             sum_of_randoms+=x;
  29.             misseds.push_back(x);
  30.         }
  31.         if(sum_of_randoms==sum_of_missed)
  32.             return misseds;
  33.         else misseds.clear();        
  34.     }
  35.  
  36. }
  37.  
  38. int main()
  39. {
  40.  
  41.     std::vector<int> vec={1,5,6,3,5,6,3,1,2,4,6,4,5};
  42.  
  43.     auto res=solution(vec,4,5);
  44.  
  45.     std::for_each(res.begin(),res.end(),[](int e){std::cout<<e<<"\t";});
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement