Skip to content

Instantly share code, notes, and snippets.

@SnowyPainter
Created May 9, 2021 03:27
Show Gist options
  • Save SnowyPainter/a0fc8189a453580b0d656e96dde1676e to your computer and use it in GitHub Desktop.
Save SnowyPainter/a0fc8189a453580b0d656e96dde1676e to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
//알고리즘 문제해결전략
//록 페스티벌
//풀이 핵심
// 1. 기능을 따로 보라
// 2. 필요에 의해 하라
int main()
{
int c;
float *results = new float[c];
cin >> c;
for (int i = 0; i < c; i++)
{
int n, l;
cin >> n >> l;
int *lend_costs = new int[n];
for (int j = 0; j < n; j++)
{
cin >> lend_costs[j];
}
float min_cost_mean = 100;
for (int j = 0; j < n; j++)
{
if (j + l >= n)
break;
for (int o = 0; o < n - (j + l); o++)
{
float cost_sum = 0;
for (int k = j; k < l + j + o; k++)
{
cost_sum += lend_costs[k];
}
float d = cost_sum / (l + o);
if (min_cost_mean > d)
min_cost_mean = d;
}
}
results[i] = min_cost_mean;
}
for (int i = 0; i < c; i++)
cout << results[i] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment