Topcoder SRM 479 "TheCoffeeTimeDivTwo"
問題:http://www.topcoder.com/stat?c=problem_statement&pm=11029 (要ログイン)
とりあえず貼っとく.
import java.util.Arrays; public class TheCoffeeTimeDivTwo { public int find(int n, int[] tea) { Arrays.sort(tea); int[] coffee = new int[n-tea.length]; for(int i = 1,p=0; i <= n; ++i){ if(Arrays.binarySearch(tea, i)<0){ coffee[p++]=i; } } return f(tea)+f(coffee); } private int f(int[] cup) { int time = 0; for(int i = cup.length-1; i >= 0;){ int j = Math.max(0, i-7+1); time += 47+2*(cup[i])+(i - j+1)*4; i = j-1; } return time; } }