-
Codeforces Round #466 (Div. 2) - A. Points on the line코드포스(CodeForce) 2018. 8. 17. 18:10반응형
1. 문제
2. 알고리즘
키워드 - 구현
* 문제 이해
첫 번째 라인에 입력되는 정수는 POINT 의 개수 와 지름을 뜻함
두 번째 라인에 입력 되는 정수는 각 점의 위치
* 문제 접근
입력 된 점의 위치에서 각 점이 사이 간격(지름)을 구하고 해당 점 사이의 점의 양을 제외 한 나머지 점을 삭제 해야 하는데 가장 작은 양의 점을 삭제 하는 횟수를 출력.
* 이해 못했던 점
C8 짜증나게 오름 차순으로 정렬 안하면 계속 틀려서 빡쳤음
처음부터 문제 요구사항에 정렬되어 있다고 나오던지 아니면 좀 안되어 있다고 나오던지 문제 이해하는데 1시간 걸림.
3. 코드
123456789101112131415161718192021222324252627282930313233343536#include <stdio.h>#include <iostream>#include <vector>#include <algorithm>#include <functional>#include <string>using namespace std;int main() {int n, dist;cin >> n >> dist;vector<int> arr(n);for (int i = 0; i<n; i++)cin >> arr[i];sort(arr.begin(), arr.end());int sol = -1;for (int i = 0; i<n; i++) {for (int j = i; j<n; j++) {if (arr[j] - arr[i] <= dist) {sol = max(sol, j-i +1);}}}cout << n - sol << endl;return 0;}cs 반응형'코드포스(CodeForce)' 카테고리의 다른 글
Codeforces Round #467 (Div. 2) - A. Olympiad (0) 2018.08.17 Educational Codeforces Round 29 - A. Quasi-palindrome (0) 2018.08.17 Educational Codeforces Round 28 - A. Curriculum Vitae (0) 2018.08.17 Educational Codeforces Round 27 - A. Chess Tourney (0) 2018.08.17 Educational Codeforces Round 26 - A. Text Volume (0) 2018.08.17