• 문제 링크
10657번: Cow Jog
The cows are out exercising their hooves again! There are N cows jogging on an infinitely-long single-lane track (1 <= N <= 100,000). Each cow starts at a distinct position on the track, and some cows jog at different speeds. With only one lane in the tr
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
Stack<Integer> stk = new Stack<>();
while (n-- > 0) {
int speed = Integer.parseInt(br.readLine().split(" ")[1]);
while (!stk.empty() && stk.peek() > speed) stk.pop();
stk.push(speed);
}
bw.write(String.valueOf(stk.size()));
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 23568 Find the House - Data Structure / Java (0) | 2023.07.01 |
---|---|
[백준] 10654 Cow Jog - Data Structure / Java (0) | 2023.06.30 |
[백준] 10527 Judging Troubles - Data Structure / Java (0) | 2023.06.29 |
[백준] 15233 Final Score - Data Structure / Java (0) | 2023.06.28 |
[백준] 13915 Hot Air Ballooning - Data Structure / Java (0) | 2023.06.27 |
댓글