| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- C
- 백준
- BOJ
- 일기
- C++
- 이득우의 게임수학
- hanbit.co.kr
- 밑바닥부터 만드는 컴퓨팅 시스템 2판
- unity6
- 주우석
- 이득우
- Shimon Schocken
- (주)책만
- 입출력과 사칙연산
- C#
- JavaScript
- 잡생각 정리글
- 게임 수학
- https://insightbook.co.kr/
- 박기현
- 데이터 통신과 컴퓨터 네트워크
- 김진홍 옮김
- 알고리즘
- 생능출판
- The Elements of Computing Systems 2/E
- HANBIT Academy
- Noam Nisan
- 전공자를 위한 C언어 프로그래밍
- 메타버스
- booksr.co.kr
Archives
- Today
- Total
cyphen156
백준-약수, 배수와 소수 2485 가로수 본문
주어진 자료에서 거리를 측정하여 최소 간격을 찾아 비어있는 부분에 추가로 자료를 넣어 같은 간격으로 채우기
제약사항
- 2 < N(Input Size) <= 100,000
- 0 < InputCase <= 1,000,000,000
- There is No Duplicate
주의 사항
없다.CPP풀이
가로수_2485.cpp
/**
* 백준 가로수_2485
* 주어진 자료에서 거리를 측정하여 최소 간격을 찾아 비어있는 부분에 추가로 자료를 넣어 같은 간격으로 채우기
*
* 제한사항
*****************************************
* 2 < N(Input Size) <= 100,000 *
* 0 < InputCase <= 1,000,000,000 *
* There is No Duplicate *
*****************************************
*
*
*
* 주의
* 없다.
*
* 풀이시간 60분
*/
#include <iostream>
#include <algorithm>
using namespace std;
static int arr[100000];
static int dist[100000];
int GCD(int a, int b);
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
for (int i = 0; i < N; ++i)
{
cin >> arr[i];
}
sort(arr, arr + N);
// 거리 차이 찾기
for (int i = 0; i < N-1; ++i)
{
dist[i] = arr[i+1] - arr[i];
}
int minDist = dist[0];
for (int i = 0; i < N-1; ++i)
{
minDist = GCD(minDist, dist[i]);
}
int count = 0;
for (int i = 0; i < N-1; ++i)
{
count += (dist[i] / minDist) -1;
}
cout << count << '\n';
return 0;
}
int GCD(int a, int b)
{
while(b != 0)
{
int temp = a % b;
a = b;
b= temp;
}
return a;
}
모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리에 있습니다.
Workspace/알고리듬 풀이 at main · cyphen156/Workspace
Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.
github.com
'컴퓨터공학 > 알고리듬 풀이' 카테고리의 다른 글
| 백준-약수, 배수와 소수 2단계 1929 소수 구하기 (0) | 2025.06.09 |
|---|---|
| 백준-약수, 배수와 소수 2단계 4134 다음 소수 (0) | 2025.06.09 |
| 백준-약수, 배수와 소수 2단계 1735 분수합 (0) | 2025.06.04 |
| 백준-약수, 배수와 소수 2단계 13241 최소공배수 (0) | 2025.06.04 |
| 백준-약수, 배수와 소수 2단계 1934 최소공배수 (0) | 2025.06.04 |