From ba353681322a2692452c56b2ec998b52286f2b04 Mon Sep 17 00:00:00 2001 From: unlockable Date: Wed, 29 Nov 2023 16:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E4=BB=80=E4=B9=88=E6=9A=B4=E5=8A=9B?= =?UTF-8?q?=E9=83=BDwa=EF=BC=9F=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2023206/correct.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/2023206/correct.cpp b/2023206/correct.cpp index f2196ce..c921c5c 100644 --- a/2023206/correct.cpp +++ b/2023206/correct.cpp @@ -1,33 +1,19 @@ #include int* stairs = NULL; -bool* visited = NULL; int M, K, H; long long total = 0; -int dfs(int start) { - if (visited[start]) { - return 0; - } - visited[start] = true; - for (int i = 1; start + i < M && i <= K; i++) { - if (((stairs[start + i] - stairs[start]) < 0 ? stairs[start] - stairs[start + i] : stairs[start + i] - stairs[start]) <= H) { - total++; - dfs(start + i); - } - } - return 0; -} - int main() { scanf("%d %d %d", &M , &K, &H); stairs = new int[M]; - visited = new bool[M]; for (int i = 0; i < M ; i++) { scanf("%d", &stairs[i]); } for (int i = 0; i < M; i++) { - if (!visited[i]) { - dfs(i); + for (int j = i + 1; j <= i + K && j < M; j++) { + if (stairs[j] <= stairs[i] + H && stairs[j] >= stairs[i] - H) { + total++; + } } } printf("%lld", total);