为什么暴力都wa??
This commit is contained in:
@@ -1,33 +1,19 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
int* stairs = NULL;
|
int* stairs = NULL;
|
||||||
bool* visited = NULL;
|
|
||||||
int M, K, H;
|
int M, K, H;
|
||||||
long long total = 0;
|
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() {
|
int main() {
|
||||||
scanf("%d %d %d", &M , &K, &H);
|
scanf("%d %d %d", &M , &K, &H);
|
||||||
stairs = new int[M];
|
stairs = new int[M];
|
||||||
visited = new bool[M];
|
|
||||||
for (int i = 0; i < M ; i++) {
|
for (int i = 0; i < M ; i++) {
|
||||||
scanf("%d", &stairs[i]);
|
scanf("%d", &stairs[i]);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < M; i++) {
|
for (int i = 0; i < M; i++) {
|
||||||
if (!visited[i]) {
|
for (int j = i + 1; j <= i + K && j < M; j++) {
|
||||||
dfs(i);
|
if (stairs[j] <= stairs[i] + H && stairs[j] >= stairs[i] - H) {
|
||||||
|
total++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("%lld", total);
|
printf("%lld", total);
|
||||||
|
|||||||
Reference in New Issue
Block a user