fork download
  1. const char* pieceTypes[] = {
  2. "0 1 .", //0
  3. "0 2 .", //1
  4. "0 3 .", //2
  5. "0 1 2 .", //3
  6. "0 1 3 .", //4
  7. "0 1 4 .", //5
  8. "0 1 2 3 .", //6
  9. "0 1 2 4 .", //7
  10. "0 1 3 4 .", //8
  11. "0 1 ; 2 3 .", //9
  12. "0 1 2 3 4 .", //10
  13. "0 1 2 3 4 5 .", //11
  14. "0 1 ; 2 3 ; 4 5 ." //12
  15. };
  16.  
  17. static int numberOfTitles(int radius){
  18. return 3 * (radius * radius + radius);
  19. }
  20.  
  21. class PipesCase : public TestCase {
  22. public:
  23. PipesCase(){};
  24. PipesCase(int r){radius = r;};
  25.  
  26. void addTitle(int t){ titles.push_back(pieceTypes[t]);}
  27.  
  28. void randomize(){
  29. random_shuffle(titles.begin(), titles.end());
  30. }
  31.  
  32. string toString(){
  33. stringstream ss;
  34.  
  35. randomize();
  36.  
  37. ss << radius << endl;
  38. for (vector<const char*>::iterator it = titles.begin(); it != titles.end(); it++){
  39. ss << *it << endl;
  40. }
  41. ss << endl;
  42. return ss.str();
  43.  
  44. }
  45.  
  46. private:
  47. vector<const char*> titles;
  48. int radius;
  49. };
  50.  
  51.  
  52. PipesCase* trulyRandomCase(int radius){
  53. PipesCase* myCase = new PipesCase(radius);
  54. for (int i=0; i < numberOfTitles(radius); i++) myCase->addTitle(rand()%13);
  55. return myCase;
  56. }
  57.  
  58. PipesCase* sparseRandomCase(int radius){
  59. PipesCase* myCase = new PipesCase(radius);
  60. for (int i=0; i < numberOfTitles(radius); i++){
  61. if (i%3 != 0) myCase->addTitle(rand()%6); // 2/3 of the pieces are from range 0-5
  62. else myCase->addTitle(rand()%13);
  63. }
  64. return myCase;
  65. }
  66.  
  67. PipesCase* denseRandomCase(int radius){
  68. PipesCase* myCase = new PipesCase(radius);
  69. for (int i=0; i < numberOfTitles(radius); i++){
  70. if (i%3 != 0) myCase->addTitle(rand()%6 + 6); // 2/3 of the pieces are from range 6 - 11
  71. else myCase->addTitle(rand()%13);
  72. }
  73. return myCase;
  74. }
  75.  
  76. PipesCase* disjointRandomCase(int radius){
  77. PipesCase* myCase = new PipesCase(radius);
  78. for (int i=0; i < numberOfTitles(radius); i++){
  79. if (i%3 == 0) myCase->addTitle(9); // 1/3 of the pieces are type 9
  80. else if (i%3 == 1) myCase->addTitle(12); //and 1/3 is of type 12
  81. else myCase->addTitle(rand()%13);
  82. }
  83. return myCase;
  84. }
  85.  
  86.  
  87. void randomCases(TestSet &cases){
  88. for (int i = 1; i <= 19; i += 6){
  89. cases.addTestCase(trulyRandomCase(i));
  90. cases.addTestCase(sparseRandomCase(i));
  91. cases.addTestCase(denseRandomCase(i));
  92. cases.addTestCase(disjointRandomCase(i));
  93. }
  94. }
  95.  
  96. void bigRandomCases(TestSet &cases){
  97. cases.addTestCase(sparseRandomCase(25));
  98. cases.addTestCase(disjointRandomCase(25));
  99. }
  100.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty