※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26849번 문제인 Non Classical Problem이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26849
26849번: Non Classical Problem
Usually, the easiest problem in a contest, especially in the practice session, is to find either the minimum integer, the maximum integer, or the sum of a given multiset of integers. We find that such problem is too classical and too boring. Since this is
www.acmicpc.net
입력으로 주어지는 유리수들의 최솟값과 최댓값, 그리고 합을 구하는 문제이다.
gcc에서 long double 자료형을 사용하면 이와 같은 연산에서 주어진 오차범위 내의 답을 충분히 구해낼 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long double ld;
int N;
ld mx = -2000000007, mn = 2000000007, sum;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
while (N--) {
ld x, y; cin >> x >> y;
x /= y;
mx = max(mx, x), mn = min(mn, x), sum += x;
}
cout << fixed;
cout.precision(10);
cout << mn << ' ' << mx << ' ' << sum;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 13701 // C++] 중복 제거 (0) | 2022.12.27 |
---|---|
[BOJ 24196 // C++] Gömda ord (0) | 2022.12.27 |
[BOJ 26770 // C++] Basen (0) | 2022.12.26 |
[BOJ 13700 // C++] 완전 범죄 (0) | 2022.12.26 |
[BOJ 26005 // C++] 나뭇잎 학회 (0) | 2022.12.26 |