fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <random>
  5.  
  6. typedef std::vector<std::size_t> Vec;
  7.  
  8. Vec MakeData(std::size_t N){
  9. Vec V(N);
  10. std::size_t i = 0;
  11.  
  12. for (auto& o : V) o = i++;
  13.  
  14. return V;
  15.  
  16. }
  17.  
  18. bool BlockMove(Vec& vec, std::size_t P, std::size_t Len){
  19. P = std::min(P, vec.size());
  20. Len = std::min(Len, vec.size()-P);
  21.  
  22. Vec T;
  23.  
  24. for (size_t i = P; i < P+Len; i++) T.push_back(vec[i]);
  25. for (size_t i = 0; i < P; i++) T.push_back(vec[i]);
  26. for (size_t i = P+Len; i < vec.size(); i++) T.push_back(vec[i]);
  27.  
  28. vec = T;
  29.  
  30. return true;
  31.  
  32. }
  33.  
  34. bool HandShuffle(Vec& vec){
  35. std::random_device rd;
  36. std::mt19937 mt(rd());
  37. //std::mt19937 mt(0);
  38. std::uniform_int_distribution<int> uid(2, 8);
  39.  
  40. int P = 0;
  41. int Len = vec.size();
  42.  
  43. while (Len > 0){
  44. P += uid(mt);
  45. Len -= uid(mt);
  46.  
  47. Len = std::max(Len, 0);
  48. P = std::min<int>(P, vec.size() - Len);
  49.  
  50. BlockMove(vec, P, Len);
  51. }
  52.  
  53. return true;
  54. }
  55.  
  56. bool MakeHoge(Vec& vec,std::size_t N){
  57.  
  58. for (size_t i = 0; i < N; i++)
  59. {
  60. HandShuffle(vec);
  61. }
  62.  
  63. return true;
  64. }
  65.  
  66. bool Show(Vec vec){
  67. std::cout << "Result:";
  68. for (auto& o : vec) std::cout << o << ',';
  69. std::cout << std::endl;
  70.  
  71. return true;
  72. }
  73.  
  74. int main(){
  75. Vec vec = MakeData(53);
  76. MakeHoge(vec, 5);
  77. Show(vec);
  78. std::cout << std::endl;
  79. std::sort(vec.begin(), vec.end());//デバッグ用
  80. Show(vec);
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
Result:17,18,51,49,13,14,19,21,22,26,20,24,28,7,29,30,3,42,50,52,31,32,33,34,35,36,37,38,39,25,40,41,0,10,12,45,46,47,11,48,15,23,27,43,44,1,2,4,5,6,8,9,16,

Result:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,