Archives
Recent Posts
«   2024/05   »
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
11번가
Today
Total
05-18 00:01
관리 메뉴

smwhee

[코딩도장_문제94] 가성비 최대화 본문

Development

[코딩도장_문제94] 가성비 최대화

smwhee 2017. 9. 20. 00:00

package codingDojang;


import java.util.Arrays;

import java.util.Comparator;


/*

 * 가성비 최대화

 * 

 * 기계를 구입하려 하는데 이 기계는 추가 부품을 장착할 수 있다. 추가 부품은 종류당 하나씩만 장착 가능하고, 모든 추가 부품은 동일한 가격을 가진다.

 * 원래 기계의 가격과 성능, 추가 부품의 가격과 각 부품의 성능이 주어졌을 때, 추가 부품을 장착하여 얻을 수 있는 최대 가성비를 정수 부분까지 구하시오(가격 및 성능은 상대적인 값으로 수치화되어 주어진다).

 * 

 * e.g.)

 * 원래 기계의 가격 : 10

 * 원래 기계의 성능 : 150

 * 추가 부품의 가격 : 3

 * 추가 부품의 성능 : 각각 30, 70, 15, 40, 65

 * 추가 부품을 장착하여 얻을 수 있는 최대 가성비 : 17.81... → 17

 * (성능이 70과 65인 부품을 장착하면 됨)

 */


public class Question_094 {

public static void main(String[] argv) {

//가성비 = 성능/가격

int orgMachinePrice = 10;

int orgPerformance = 150;

int partsPrice = 3;

Integer[] partsPerformance = {30, 70, 15, 40 ,65};;

int machinePrice = orgMachinePrice;

double costEffectiveness = orgPerformance / orgMachinePrice;

int len = partsPerformance.length;

Arrays.sort(partsPerformance, new Ascending());

for(int i = 0; i < len; i++) {

orgPerformance += partsPerformance[i];

machinePrice += partsPrice;

double temp = (double)orgPerformance / machinePrice;

if(costEffectiveness < temp) {

costEffectiveness = temp;

}

}

System.out.println((int)costEffectiveness);

}

static class Ascending implements Comparator {

public int compare(Object o1, Object o2) {

if(o1 instanceof Comparable && o2 instanceof Comparable) {

Comparable c1 = (Comparable)o1;

Comparable c2 = (Comparable)o2;


return c2.compareTo(c1);

}

return -1;

}

}

}



Comments