2011年4月26日火曜日

SRM 145 DIV1 | 122.11/250

数字列を割合に変換し、あまりをポイント高い順に振り分ける
[java]
public class Bonuses {
public int[] getDivision(int[] points) {
int total = 0;
int max = 0;
for(int point : points) {
total += point;
max = Math.max(max, point);
}

int[] division = new int[points.length];
for(int i = 0; i division[i] = (points[i] * 100) / total;

int divtotal = 0;
for(int div : division)
divtotal += div;

int rest = 100 - divtotal;
loop:while(max > 0 && rest>0) {
for( int i=0; i0; i++) {
int plus = (points[i]==max) ? 1 : 0;
division[i] += plus;
rest -= plus;
}
max--;
}
return division;
}
}
[/java]

0 件のコメント:

コメントを投稿