Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions week40/이상억/backjoon/2배_또는_0.5배.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.*;
import java.io.*;

public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


int N = Integer.parseInt(br.readLine());



}
}


//
56 changes: 56 additions & 0 deletions week40/이상억/backjoon/숫자_고르기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import java.util.*;
import java.io.*;

public class Main {

static int[] next;
static boolean[] visited;
static boolean[] finished;
static List<Integer> answer = new ArrayList<>();

static void dfs(int cur) {
visited[cur] = true;
int nxt = next[cur];

if (!visited[nxt]) {
dfs(nxt);
}
else if (!finished[nxt]) {
int temp = nxt;
answer.add(temp);

while (temp != cur) {
temp = next[temp];
answer.add(temp);
}
}

finished[cur] = true;
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int N = Integer.parseInt(br.readLine());

next = new int[N + 1];
visited = new boolean[N + 1];
finished = new boolean[N + 1];

for (int i = 1; i <= N; i++) {
next[i] = Integer.parseInt(br.readLine());
}

for (int i = 1; i <= N; i++) {
if (!visited[i]) {
dfs(i);
}
}

Collections.sort(answer);
System.out.println(answer.size());
for (int x : answer) {
System.out.println(x);
}
}
}
56 changes: 56 additions & 0 deletions week40/이상억/progarmmers/섬_연결하기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import java.util.*;

class Solution {

class Edge {
int to;
int cost;

Edge(int to, int cost) {
this.to = to;
this.cost = cost;
}
}

public int solution(int n, int[][] costs) {

List<Edge>[] graph = new ArrayList[n];
for (int i = 0; i < n; i++) {
graph[i] = new ArrayList<>();
}

for (int[] c : costs) {
int from = c[0];
int to = c[1];
int cost = c[2];

graph[from].add(new Edge(to, cost));
graph[to].add(new Edge(from, cost));
}

boolean[] visited = new boolean[n];
PriorityQueue<Edge> pq = new PriorityQueue<>(
(a, b) -> a.cost - b.cost
);

pq.add(new Edge(0, 0));
int answer = 0;

while (!pq.isEmpty()) {
Edge cur = pq.poll();

if (visited[cur.to]) continue;

visited[cur.to] = true;
answer += cur.cost;

for (Edge next : graph[cur.to]) {
if (!visited[next.to]) {
pq.add(next);
}
}
}

return answer;
}
}
73 changes: 73 additions & 0 deletions week40/이상억/progarmmers/추석_트래픽.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.util.*;

class Solution {

static class Log{
int start;
int end;

Log(int start, int end){
this.start = start;
this.end = end;
}
}


static Log parse(String line){
String[] parts = line.split(" ");

String[] time = parts[1].split(":");

int hh = Integer.parseInt(time[0]);
int mm = Integer.parseInt(time[1]);

String[] sec = time[2].split("\\.");
int ss = Integer.parseInt(sec[0]);
int ms = Integer.parseInt(sec[1]);

int endMs = hh * 3600000 +
mm * 60000 +
ss * 1000 +
ms;

double durationSec = Double.parseDouble(
parts[2].substring(0, parts[2].length() - 1)
);

int durationMs = (int)(durationSec * 1000);

int startMs = endMs - durationMs + 1;

return new Log(startMs, endMs);

}


public int solution(String[] lines) {
int answer = 0;

List<Log> logs = new ArrayList<>();

for(String line : lines){
logs.add(parse(line));
}

for(Log base : logs){
int windowStart = base.end;
int windowEnd = base.end + 999;

int count = 0;
for(Log target : logs){
if(target.start <= windowEnd && target.end >= windowStart){
count ++;
}
}

answer = Math.max(answer, count);
}
return answer;
}
}

// window : [======]
// target : [-----------]