[알고스팟] 록 페스티벌 C#
Algorithm 2023. 1. 17. 15:11
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _4458
{
class Program
{
static void Main(string[] args)
{
int[] nl = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int n = nl[0];
int l = nl[1];
int[] arr = { 0, };
arr = arr.Concat(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse)).ToArray();
Console.WriteLine(arr.Length);
//for (int i = 0; i < arr.Length; i++) Console.Write("{0} ", arr[i]);
int[] psum = new int[n + 1];
for (int i = 1; i < n+1; i++) {
psum[i] = psum[i - 1] + arr[i];
}
for (int i = 0; i < psum.Length; i++) Console.Write("{0} ", psum[i]);
//입력
//6 3
//1 2 3 1 2 3
//arr : 0 1 2 3 1 2 3
//psum : 0 1 3 6 7 9 12
//3일 : (1,2,3), (2,3,1), (3,1,2), (1,2,3)
// 1-3 2-4 3-5 4-6
//4일 : (1,2,3,1), (2,3,1,2), (3,1,2,3)
// 1-4 2-5 3-6
//5일 : (1,2,3,1,2), (2,3,1,2,3)
// 1-5 2-6
//6일 : (1,2,3,1,2,3)
// 1-6
Console.WriteLine();
double allOfMinAvg = double.MaxValue;
for (int i = l; i < n + 1; i++) {
Console.Write("{0}일 : ", i);
int s = 0; //start
double dayOfMinAvg = double.MaxValue;
for (int j = i; j < n+1; j++) {
s += 1;
int sum = psum[j] - psum[s - 1];
double avg = (double)sum / i;
Console.Write("{0}-{1} : {2}, {3}\t", s, j, sum, avg);
dayOfMinAvg = Math.Min(dayOfMinAvg, avg);
}
Console.Write("dayOfMinAvg : {0}\t", dayOfMinAvg);
allOfMinAvg = Math.Min(allOfMinAvg, dayOfMinAvg);
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine("allOfMinAvg: {0}", allOfMinAvg.ToString("F11"));
Console.WriteLine();
}
}
}
https://www.algospot.com/judge/problem/read/FESTIVAL
cpp 버전
#include<iostream>
using namespace std;
int main()
{
int c, n, l;
cin >> c;
while (c--) {
cin >> n >> l;
int psum[1001] = { 0, };
int cost;
for (int i = 1; i <= n; i++) {
cin >> cost;
psum[i] = psum[i - 1] + cost;
}
double allOfMinAvg = 10000;
for (int i = l; i < n + 1; i++) {
int s = 0; //start
double dayOfMinAvg = 10000;
for (int j = i; j < n + 1; j++) {
s += 1;
int sum = psum[j] - psum[s - 1];
double avg = (double)sum / i;
dayOfMinAvg = min(dayOfMinAvg, avg);
}
allOfMinAvg = min(allOfMinAvg, dayOfMinAvg);
}
//cout << allOfMinAvg << "\n";
printf("%0.9lf\n", allOfMinAvg);
}
return 0;
}
'Algorithm' 카테고리의 다른 글
[BOJ] 10845 큐 (0) | 2023.01.17 |
---|---|
[BOJ] 1406 에디터 (0) | 2023.01.17 |
BST (Binary Search Tree) (0) | 2023.01.16 |
LCRS Tree (0) | 2023.01.16 |
[BOJ] 1874 스택 수열 (0) | 2023.01.16 |