-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 정수 제곱근 판별 * 게임 맵 최단거리 * 주차 요금 계산 * 셔틀 버스
- Loading branch information
1 parent
2cb80fc
commit 27dc670
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 가장 마지막 타임 or 자리가 부족하다면 마지막으로 타는 크루 시간 -1분 | ||
import java.util.*; | ||
|
||
class Solution { | ||
public String solution(int n, int t, int m, String[] timetable) { | ||
int answer = convertToMin("9:00") + t * (n-1); | ||
ArrayDeque<Integer> dq = new ArrayDeque<>(); | ||
Arrays.sort(timetable); | ||
for (String time: timetable) { | ||
dq.add(convertToMin(time)); | ||
} | ||
|
||
int lastTime = 0; | ||
int count = 0; | ||
for (int i=0;i<n;i++) { | ||
int shuttle = convertToMin("9:00") + t*i; | ||
count = 0; | ||
while (count < m && !dq.isEmpty() && dq.peekFirst() <= shuttle) { | ||
count++; | ||
lastTime = dq.removeFirst(); | ||
} | ||
} | ||
|
||
if (count == m) { | ||
answer = lastTime - 1; | ||
} | ||
return convertToTime(answer); | ||
} | ||
|
||
int convertToMin(String s) { | ||
String[] temp = s.split(":"); | ||
int h = Integer.parseInt(temp[0]); | ||
int m = Integer.parseInt(temp[1]); | ||
return h * 60 + m; | ||
} | ||
|
||
String convertToTime(int min) { | ||
String h = "0"+String.valueOf(min / 60); | ||
String m = "0"+String.valueOf(min % 60); | ||
return h.substring(h.length()-2) + ":" + m.substring(m.length()-2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
int[][] dxdy = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; | ||
public int solution(int[][] maps) { | ||
int n = maps.length; | ||
int m = maps[0].length; | ||
int[][] graph = new int[n][m]; | ||
|
||
ArrayDeque<int[]> dq = new ArrayDeque<>(); | ||
dq.addLast(new int[]{0, 0}); | ||
graph[0][0] = 1; | ||
|
||
int answer = 0; | ||
while (!dq.isEmpty()) { | ||
int[] temp = dq.removeFirst(); | ||
int x = temp[0]; | ||
int y = temp[1]; | ||
if (x == n-1 && y == m-1) { | ||
answer = graph[x][y]; | ||
break; | ||
} | ||
for (int[] d: dxdy) { | ||
int _x = x + d[0]; | ||
int _y = y + d[1]; | ||
if (_x < 0 || _x >= n || _y < 0 || _y >= m) { | ||
continue; | ||
} | ||
if (maps[_x][_y] == 0 || graph[_x][_y] > 0) { | ||
continue; | ||
} | ||
graph[_x][_y] = graph[x][y] + 1; | ||
dq.addLast(new int[]{_x, _y}); | ||
} | ||
} | ||
if (answer > 0) { | ||
return answer; | ||
} | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Solution { | ||
public long solution(long n) { | ||
double root = Math.sqrt(n); | ||
if (root == (long)root) { | ||
return (long)Math.pow(root+1, 2); | ||
} | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import java.util.*; | ||
|
||
class Solution { | ||
|
||
int basicTime; | ||
int basicFee; | ||
int unitTime; | ||
int unitFee; | ||
int MAX_TIME = convert("23:59"); | ||
|
||
public int[] solution(int[] fees, String[] records) { | ||
|
||
basicTime = fees[0]; | ||
basicFee = fees[1]; | ||
unitTime = fees[2]; | ||
unitFee = fees[3]; | ||
|
||
HashMap<String, Integer> inMap = new HashMap<>(); | ||
TreeMap<String, Integer> timeMap = new TreeMap<>(); | ||
|
||
for (String record: records) { | ||
StringTokenizer st = new StringTokenizer(record); | ||
int t = convert(st.nextToken()); | ||
String car = st.nextToken(); | ||
String info = st.nextToken(); | ||
|
||
if (info.equals("IN")) { | ||
inMap.put(car, t); | ||
} else { | ||
int in = inMap.get(car); | ||
timeMap.put(car, timeMap.getOrDefault(car, 0)+t-in); | ||
inMap.remove(car); | ||
} | ||
} | ||
|
||
for (String car: inMap.keySet()) { | ||
int in = inMap.get(car); | ||
timeMap.put(car, timeMap.getOrDefault(car, 0)+MAX_TIME-in); | ||
} | ||
|
||
ArrayList<Integer> answer = new ArrayList<>(); | ||
for (String car: timeMap.keySet()) { | ||
answer.add(calculateFee(timeMap.get(car))); | ||
} | ||
|
||
return answer.stream().mapToInt(x->x).toArray(); | ||
} | ||
|
||
private int calculateFee(int t) { | ||
int fee = basicFee; | ||
if (basicTime < t) { | ||
fee += Math.ceil((t - basicTime) / (double)unitTime) * unitFee; | ||
} | ||
return fee; | ||
} | ||
|
||
private int convert(String s) { | ||
StringTokenizer st = new StringTokenizer(s, ":"); | ||
int h = Integer.parseInt(st.nextToken()); | ||
int m = Integer.parseInt(st.nextToken()); | ||
return h * 60 + m; | ||
} | ||
} |