fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. //first place to start point
  5. //second place to end point
  6. //each value means stacked sum
  7. double stackSequence[1000][1000] = { 0 };
  8. int cost[1000] = { 0 };
  9. double ans[50] = { 0 };
  10.  
  11. double getLeasetValue(int* cost, int numofdays, int numofteams)
  12. {
  13. //save all possible value in array
  14. for (int i = 0; i < numofdays - numofteams+1; i++)
  15. {
  16. stackSequence[i][i] = cost[i];
  17. for (int j = i; j < numofdays; j++)
  18. {
  19. if (cost[j + 1] == 0)
  20. break;
  21. stackSequence[i][j + 1] = stackSequence[i][j] + cost[j + 1];
  22. }
  23. }
  24.  
  25. //get least value from array in this variable
  26. double leastvalue = stackSequence[0][numofteams - 1] / numofteams;
  27.  
  28. for (int i = 0; i < numofdays - numofteams; i++)
  29. {
  30. double temp = 0;
  31. for (int j = i + numofteams; j < numofdays; j++)
  32. {
  33. temp = stackSequence[i][j] / (j - i + 1);
  34. if (leastvalue > temp)
  35. leastvalue = temp;
  36. }
  37. }
  38.  
  39. return leastvalue;
  40.  
  41. }
  42.  
  43.  
  44. int main()
  45. {
  46. int testcasenum = 0;
  47. if (testcasenum < 50)
  48. {
  49. cin >> testcasenum;
  50. for (int i = 0; i < testcasenum; i++)
  51. {
  52. int n = 0; //numofdays
  53. int m = 0; //numofteams
  54. cin >> n >> m;
  55.  
  56. if (n <= 0 || n > 1000)
  57. {
  58. cout << "대여할 수 있는 날은 1일 이상 1000일 이하여야 합니다" << endl;
  59. exit(1);
  60. }
  61.  
  62. if (m > n || m <= 0 || m > 1000)
  63. {
  64. cout << "섭외한 공연 팀의 수는 대여할 수 있는 날보다 적어야 하고 1팀 이상 1000팀 이하여야 합니다" << endl;
  65. exit(1);
  66. }
  67.  
  68. for (int i = 0; i < n; i++)
  69. {
  70. cin >> cost[i];
  71. }
  72.  
  73.  
  74. //set sequence value by func and get least sequence value
  75. ans[i] = getLeasetValue(cost, n, m);
  76. int temp1 = ans[i];
  77. }
  78.  
  79. for (int i = 0; i < testcasenum; i++)
  80. {
  81. printf("%.8lf\n", ans[i]);
  82. }
  83. }
  84.  
  85. int hi;
  86. cin >> hi;
  87. return 0;
  88. }
  89.  
  90.  
Success #stdin #stdout 0s 23056KB
stdin
2
6 3
1 2 3 1 2 3
6 2
1 2 3 1 2 3
stdout
1.75000000
1.50000000