본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 10180 : Ship Selection

반응형

https://www.acmicpc.net/problem/10180

 

10180번: Ship Selection

Input begins with a line with one integer T (1 ≤ T ≤ 50) denoting the number of test cases. Each test case begins with a line with two space-separated integers N and D, where N (1 ≤ N ≤ 100) denotes the number of ships in the docking bay and D (1

www.acmicpc.net

구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

testcase 수 t, 선박 수 n, 도착지까지의 거리 d, 선박속도 v, 선박 잔여 연료 f, 시간 당 연료 소모량 c를 선언해줍니다.다음으로 while loop를 수행하며 n, d에 입력받습니다.

📔 풀이과정

 1. 매 선박 정보를 입력받을 때마다 해당 선박이 유효한지 계산해줍니다.

 2. 선박이 갈 수 있는 거리는 속도 * 시간이므로 다음 공식이 성립합니다.

갈 수 있는 거리 = v * (f / c)

    갈 수 있는 거리가 d이상이라면 정답이므로 지역변수 ans값을 1씩 추가해줍니다.

📔 정답출력

ans를 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
double t, n, d, v, f, c;
int main(){
    cin >> t;
    while(t--){
        cin >> n >> d;
        int ans = 0;
        for(int i = 0; i < n; i++){
            cin >> v >> f >> c;
            double dist = v * (f / c);
            if(dist >= d) ans++;
        }
        cout << ans << '\n';
    }
}