Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 백준 25305번 커트라인
- 카운팅배열 자바
- 백준 2738 행렬덧셈
- 백준 2738
- 기본수학2
- 백준 2566 자바
- 배열
- 네트워크
- 백준
- 자바
- 백준 커트라인
- RFC1918
- 백준 5597 자바
- 백준 2738번
- counting sort java
- 백준 2587
- 백준 2750 자바
- 백준 대표값2 자바
- 백준 과제안내신분 자바
- LAN port
- 백준 25305번 커트라인 자바
- Intermediate Device
- 백준 대표값2
- 백준 최댓값 2566
- 카운팅배열
- 백준 25305번
- 백준 2587 자바
- 백준 2738 자바
- 백준 수정렬하기
- 백준 행렬덧셈
Archives
- Today
- Total
ddubi
백준 2869 : 달팽이는 올라가고 싶다 java 본문
링크
https://www.acmicpc.net/problem/2869
2869번: 달팽이는 올라가고 싶다
첫째 줄에 세 정수 A, B, V가 공백으로 구분되어서 주어진다. (1 ≤ B < A ≤ V ≤ 1,000,000,000)
www.acmicpc.net
특징
시간 제한 0.15 초 (추가 시간 없음)
풀이
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class back_2869 { // 달팽이는 올라가고 싶다
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] data = br.readLine().split(" ");
int A = Integer.valueOf(data[0]);
int B = Integer.valueOf(data[1]);
int V = Integer.valueOf(data[2]);
int day = (int) Math.ceil((V-B)/(A-B));
// ceil 올림
// floor 내림
// round 반올림
System.out.println(day);
}
}
+ 틀린풀이(1) --> while
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int up = sc.nextInt();
int down = sc.nextInt();
int goal = sc.nextInt();
int snail = 0;
int day = 0;
while (snail < goal) {
day++;
snail += up;
if (snail >= goal) {
break;
}
snail -= down;
}
System.out.println(day);
}
}
+ 틀린풀이(2) --> Scanner
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double A = sc.nextInt();
double B = sc.nextInt();
double V = sc.nextInt();
double answer = (V - B) / (A - B);
if (answer % 1 != 0) {
answer++;
}
System.out.println((int) answer);
}
}
시간 제한이 있는 문제
Scanner, while을 사용하면 시간 초과가 되어버리기 때문에 주의!
'코테 문제풀이' 카테고리의 다른 글
[백준] 18108번 1998년생인 내가 태국에서는 2541년생?! feat.java (0) | 2022.11.15 |
---|---|
백준 12685 : 평범한 배낭 java (0) | 2022.11.09 |
[백준][시간초과] 1655번 가운데를 말해요 문제풀이 feat.Java (0) | 2022.11.09 |
백준 11047 : 동전 0 (Java) (0) | 2022.10.25 |
프로그래머스 : 오랜기간 보호한 동물(2) (0) | 2022.10.25 |
Comments