SWEA 1491 원재의 벽 꾸미기

1 개요[ | ]

SWEA 1491 원재의 벽 꾸미기
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 3-6

2 C++[ | ]

3 Java[ | ]

import java.util.*;
public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int tc=1; tc<=T; tc++) {
			long N = sc.nextInt();
			long A = sc.nextInt();
			long B = sc.nextInt();
			long value, min = Long.MAX_VALUE;
			for(long C=1; C<=N/2; C++) {
				for(long R=C; C*R<=N; R++) {
					value = A*(R-C) + B*(N-R*C);
					if(value<min) min=value;
				}
			}
			System.out.format("#%d %d\n", tc, min);
		}
		sc.close();
	}
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}