[백준 24302] КУРИЕРИ (C#, C++) - soo:bak
작성일 :
문제 링크
설명
두 배송 거리에 대해 각 운송사의 요금을 계산하고, 합계가 최소가 되도록 선택하는 문제입니다.
접근법
거리 구간에 따라 요금이 달라지므로 각 거리에 대해 두 운송사의 비용을 계산한 뒤 더 작은 값을 선택합니다.
거리 기반 구간 판정은 미터 단위로 하고, 완전한 킬로미터 수는 거리를 1000으로 나눈 정수 부분으로 계산합니다.
Code
C#
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
using System;
class Program {
static double CostA(double d) {
if (d <= 5) return 4;
if (d <= 10) return 7;
if (d <= 20) return 12;
if (d <= 30) return 17;
return d * 0.57;
}
static double CostB(double d) {
if (d <= 2) return 0.9 + d * 0.9;
if (d <= 5) return 1 + d * 0.85;
if (d <= 20) return 1.25 + d * 0.8;
if (d <= 40) return 3.25 + d * 0.7;
return 9.25 + d * 0.55;
}
static void Main() {
var parts = Console.ReadLine()!.Split();
var n = int.Parse(parts[0]) / 1000;
var m = int.Parse(parts[1]) / 1000;
var ans = Math.Min(CostA(n), CostB(n)) + Math.Min(CostA(m), CostB(m));
Console.WriteLine($"{ans:F2}");
}
}
C++
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
29
30
31
#include <bits/stdc++.h>
using namespace std;
double costA(double d) {
if (d <= 5) return 4;
if (d <= 10) return 7;
if (d <= 20) return 12;
if (d <= 30) return 17;
return d * 0.57;
}
double costB(double d) {
if (d <= 2) return 0.9 + d * 0.9;
if (d <= 5) return 1 + d * 0.85;
if (d <= 20) return 1.25 + d * 0.8;
if (d <= 40) return 3.25 + d * 0.7;
return 9.25 + d * 0.55;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
n /= 1000; m /= 1000;
cout << fixed << setprecision(2);
cout << min(costA(n), costB(n)) + min(costA(m), costB(m)) << "\n";
return 0;
}