불타는 아잍(IT)스크림

Sources

Posts

12 posts

VendingMachine

Code public class VendingMachine{ int rows, cols; int ts; // a total of seconds int ci, cj; // current i, current j; int[][] p; void addSecs(int nj) { int a = Math.abs(nj - cj); int b = cols - Math.abs(nj - cj); ts += (a < b) ? a : b; } void setMaxCol() { int max = -1, mj = cj; for (int j = 0; j < cols

PenLift

Code import java.util.ArrayList; public class PenLift { int len, size; boolean[] usedS, usedV; int[] nv; // num of vertices int[][] adj1, adj2; ArrayList xv, yv; boolean contains(int x,int y) { for (int i = 0; i < xv.size(); i++) if (xv.get(i)==x && yv.get(i)==y) return true; retur

Lottery

Code import java.util.Arrays;import java.util.Comparator; public class Lottery{ long perm(long a, long b) { long num = 1; for (int i = 0; i < b; i++) num *= a--; return num; } long fact(long a) { long num = 1; for (int i = 2; i

PowerOutage

Code import java.util.LinkedList;import java.util.Queue; public class PowerOutage{ public int estimateTimeout(int[] fromJunction, int[] toJunction, int[] ductLength) { int n = fromJunction.length; int sum = 0; int len = 0; int[] dlSum = new int[50]; for (int i = 0; i < n; i++) sum += ductLength[i]; Queue q = new Link

ArithmeticSequenceDiv1

불타는 아잍(IT)스크림|2019년 12월 20일

Code public class ArithmeticSequenceDiv1 { public int findMinCost(int[] x) { int n = x.length; int min = 10000; int maxGap = 0; for (int i = 0; i < n-1; i++) if(Math.abs(x[i+1]-x[i]) > maxGap) maxGap = Math.abs(x[i+1]-x[i]); for (int d = -maxGap; d