티스토리 뷰

Algorithm

백준_사나운개_2991

Young_J 2020. 9. 13. 10:19

알고리즘

경우의 수가 2가지
* 배달시간을 (공격 + 대기)로 나눈 나머지가 0이 아닐 때 
* 나온값에 공격시간을 뺀값이 0이하면 물림

 

문제를 잘 파악하고 경우의 수만 찾아낼 수 있다면 쉽게 풀 수 있는 문제

 

package baekjoon;

import java.util.Scanner;

public class 사나운개 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A, B, C, D;
		int P, M, N;
		int result = 0;
		int result1 = 0;
		int result2 = 0;

		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		D = sc.nextInt();
		P = sc.nextInt();
		M = sc.nextInt();
		N = sc.nextInt();

		// 알고리즘
		// 2가지의 경우가 나옴
		// 배달시간을 (공격 + 대기)로 나눈 나머지가 0이 아닐 때 
		// 나온값에 공격시간을 뺀값이 0이하면 물림
		
		//ex) 4 % (2+2) = 0 //안물림
		//ex) 1 % (2+2) = 1 , 1 - 2 = -1  //물림
		//ex) 2 % (2+2) = 2 , 2 - 2 = 0 //물림
		//ex) 3 % (2+2) = 3 , 3 - 2 = 1 //안물림
		
		 

		if (P % (A + B) != 0) {
			if (P % (A + B) - A <= 0) {
				result++;
			}
		}
		if (P % (C + D) != 0) {
			if (P % (C + D) - C <= 0) {
				result++;
			}
		}

		if (M % (A + B) != 0) {
			if (M % (A + B) - A <= 0) {
				result1++;
			}
		}
		if (M % (C + D) != 0) {
			if (M % (C + D) - C <= 0) {
				result1++;
			}
		}

		if (N % (A + B) != 0) {
			if (N % (A + B) - A <= 0) {
				result2++;
			}
		}
		if (N % (C + D) != 0) {
			if (N % (C + D) - C <= 0) {
				result2++;
			}
		}

		System.out.println(result);
		System.out.println(result1);
		System.out.println(result2);

		sc.close();

	}

}

'Algorithm' 카테고리의 다른 글

백준_다리만들기_2146  (0) 2020.09.16
백준_미로탐색_2178  (0) 2020.09.15
백준_안전영역_2468  (0) 2020.09.11
백준_불_5427  (0) 2020.09.10
백준_게리맨더링_17471  (0) 2020.09.09
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/10   »
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
글 보관함