From de0721354b3bfb7f1f3ec3b5272a35ee87599ba0 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Thu, 2 Dec 2021 08:55:06 -0600 Subject: [PATCH] Complete USACO 2020 December Bronze Problem 2: Daisy Chains --- usaco/Daisy Chain/index.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/usaco/Daisy Chain/index.cpp b/usaco/Daisy Chain/index.cpp index 987a57b..6b5016f 100644 --- a/usaco/Daisy Chain/index.cpp +++ b/usaco/Daisy Chain/index.cpp @@ -4,19 +4,28 @@ using namespace std; int main() { int n; + int a = 0; cin >> n; int flower_array[n]; for (int i = 0; i < n; i++) { cin >> flower_array[i]; } - for (int i = 0; i < n - 1; i++) { - for (int j = 0; j < n - i - 1; j++) { - int k = j + i; - for (int l = 1; l <= k; l++) { - cout << flower_array[l] << " "; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n - i; j++) { + double average = 0; + for (int k = 0; k <= j; k++) { + average += flower_array[i+k]; + } + average /= (j+1); + for (int k = 0; k <= j; k++) { + if (flower_array[i+k] == average) { + a++; + break; + } } - cout << endl; } } + //a -= n; + cout << a; return 0; }