TopCoder 250 points 3-SRM 145 DIV 1 84.71/250 33.88%
来源:互联网 发布:mac pro 无法安装win7 编辑:程序博客网 时间:2024/05/17 06:06
Problem Statement
You have a certain amount of money to give out as a bonus to employees. The trouble is, who do you pick to receive what bonus? You decide to assign a number of points to each employee, which corresponds to how much they helped the company in the last year. You are given an int[] points, where each element contains the points earned by the corresponding employee (i.e. points[0] is the number of points awarded to employee 0). Using this, you are to calculate the bonuses as follows:
- First, add up all the points, this is the pool of total points awarded.
- Each employee gets a percentage of the bonus money, equal to the percentage of the point pool that the employee got.
- Employees can only receive whole percentage amounts, so if an employee's cut of the bonus has a fractional percentage, truncate it.
- There may be some percentage of bonus left over (because of the fractional truncation). If n% of the bonus is left over, give the top n employees 1% of the bonus. There will be no more bonus left after this. If two or more employees with the same number of points qualify for this "extra" bonus, but not enough bonus is left to give them all an extra 1%, give it to the employees that come first inpoints.
The return value should be a int[], one element per employee in the order they were passed in. Each element should be the percent of the bonus that the employee gets.
Definition
Class:BonusesMethod:getDivisionParameters:int[]Returns:int[]Method signature:int[] getDivision(int[] points)(be sure your method is public)Constraints
-points will have between 1 and 50 elements, inclusive.-Each element of points will be between 1 and 500, inclusive.Examples
0){1,2,3,4,5}
Returns: { 6, 13, 20, 27, 34 }The total points in the point pool is 1+2+3+4+5 = 15.
Employee 1 gets 1/15 of the total pool, or 6.66667%, Employee 2 gets 13.33333%, Employee 3 gets 20% (exactly), Employee 4 gets 26.66667%, and Employee 5 gets 33.33333%. After truncating, the percentages look like:
{6,13,20,26,33}
Adding up all the fractional percentages, we see there is 2% in extra bonuses, which go to the top two scorers. These are the employees who received 4 and 5 points.1)
{5,5,5,5,5,5}
Returns: { 17, 17, 17, 17, 16, 16 }The pool of points is 30. Each employee got 1/6 of the total pool, which translates to 16.66667%. Truncating for all employees, we are left with 4% in extra bonuses. Because everyone got the same number of points, the extra 1% bonuses are assigned to the four that come first in the array.2)
{485, 324, 263, 143, 470, 292, 304, 188, 100, 254, 296, 255, 360, 231, 311, 275, 93, 463, 115, 366, 197, 470}
Returns: { 8, 6, 4, 2, 8, 5, 5, 3, 1, 4, 5, 4, 6, 3, 5, 4, 1, 8, 1, 6, 3, 8 }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
这次好象也用了1小时
package srms1_20_r3;import java.util.Comparator;import java.util.Iterator;import java.util.Map;import java.util.TreeMap;public class Bonuses {/** * @param args */public static void main(String[] args) {int s[] = { 485, 324, 263, 143, 470, 292, 304, 188, 100, 254, 296, 255,360, 231, 311, 275, 93, 463, 115, 366, 197, 470 };int r[] = getDivision(s);for (int i = 0; i < r.length; i++)System.out.print(r[i] + ",");}public static int[] getDivision(int[] points) {TreeMap<String, Integer> map = new TreeMap<String, Integer>(new Comparator<String>() {public int compare(String s1, String s2) {String array1[] = s1.split("-");String array2[] = s2.split("-");int v1, v2, v3, v4;v1 = Integer.parseInt(array1[0]);v2 = Integer.parseInt(array1[1]);v3 = Integer.parseInt(array2[0]);v4 = Integer.parseInt(array2[1]);if (v1 > v3)return -1;else if (v1 < v3)return 1;else {if (v2 > v4)return 1;elsereturn -1;}}});int sum = 0;int len = points.length;int num = 100;int r[] = new int[len];for (int i = 0; i < len; i++)sum += points[i];for (int i = 0; i < len; i++) {r[i] = points[i] * 100 / sum;num -= r[i];map.put(points[i] + "-" + i, i);}if (num > 0) {int index = -1;Iterator titer = map.entrySet().iterator();while (titer.hasNext()) {if (num < 1) {break;}Map.Entry ent = (Map.Entry) titer.next();String keyt = ent.getKey().toString();String valuet = ent.getValue().toString();index = Integer.parseInt(valuet);r[index]++;num--;}}return r;}}
- TopCoder 250 points 3-SRM 145 DIV 1 84.71/250 33.88%
- TopCoder 250 points 4-SRM 145 DIV 2 128.72/250 51.49%
- TopCoder 250 points 9-SRM 148 DIV 1 75/250 30%
- TopCoder 250 points 11-SRM 149 DIV 1 86.62/250 34.65%
- TopCoder 250 points 13-SRM 150 DIV 1 82.63/250 33.05%
- TopCoder 250 points 15-SRM 151 DIV 1 121.73/250 48.69%
- TopCoder 250 points 17-SRM 152 DIV 1 106.51/250 42.60%
- TopCoder 250 points 19-SRM 153 DIV 1 84.72/250 33.89%
- TopCoder 250 points 6-SRM 146 DIV 2 162.67/250 65.07%
- TopCoder 250 points 8-SRM 147 DIV 2 176.36/250 70.54%
- TopCoder 250 points 10-SRM 148 DIV 2 167.20/250 66.88%
- TopCoder 250 points 12-SRM 149 DIV 2 103.92/250 41.57%
- TopCoder 250 points 14-SRM 150 DIV 2 86.25/250 34.50%
- TopCoder 250 points 16-SRM 151 DIV 2 97.63/250 39.05%
- TopCoder 250 points 18-SRM 152 DIV 2 167.05/250 66.82%
- TopCoder 250 points 20-SRM 153 DIV 2 216.58/250 86.63%
- TopCoder 250 points 28-SRM 157 DIV 2 185.60/250 74.24%
- TopCoder 300 points 24-SRM 155 DIV 2 75/250 30%
- 顺序表的简单实现
- FCKeditor实现批量上传图片
- Simplify Path
- 『MySQL』多表之间字段的匹配
- 计算机内部工作原理
- TopCoder 250 points 3-SRM 145 DIV 1 84.71/250 33.88%
- Android开发(6)--完成登陆界面的数据保存回显的操作
- 最火的Android开源项目
- 计算机中的运算
- Splay Tree源码
- 黑马程序员——内部类, 异常
- Java中断机制
- HDU 4540 威威猫系列故事——打地鼠
- linux系统的spi总线输出与AD5410/AD5420的读取