Skip to content
Open
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
87 changes: 87 additions & 0 deletions baekjoon/11967_불켜기/src/JIHANEOL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import java.io.*;
import java.util.*;

public class JIHANEOL {
static BufferedReader br;
static StringTokenizer st;
static boolean map[][],On[][];
static boolean visited[][][];

static class Point{
int x,y;

public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
}
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
int N = Integer.valueOf(st.nextToken());
int M = Integer.valueOf(st.nextToken());
List<Point>[][] list = new List[N][N];
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
list[i][j] = new ArrayList();
}
}
for(int i=0; i<M; i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.valueOf(st.nextToken());
int y = Integer.valueOf(st.nextToken());
int x1 = Integer.valueOf(st.nextToken());
int y1 = Integer.valueOf(st.nextToken());
list[x-1][y-1].add(new Point(x1-1, y1-1));
}
int turnOn = 1;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
map = new boolean[N][N];

//달이 차오른다 1억 크기 까지 만들수 있다. 메모리 몇십 매거 차지
visited = new boolean[N][N][N*N];
Queue<int[]> q = new LinkedList<int[]>();
q.add(new int[] {0,0,1});
map[0][0] = true;
visited[0][0][1] =true;
On = new boolean[N][N];
while(!q.isEmpty()) {
int[] now = q.poll();
int x = now[0];
int y = now[1];
int key = now[2];

// KEY 와 현재 turnOn과 비교
if(turnOn!=key) continue;
// 불 킬수 있으면 키자..
if(!On[x][y] && list[x][y].size()!=0) {
On[x][y] = true;
for(Point p : list[x][y]) {
if(map[p.x][p.y]==false) {
map[p.x][p.y] = true;
turnOn++;
}
}
}
for(int i=0; i<4; i++) {
int nx = x+ dx[i];
int ny = y+ dy[i];

try {
if(map[nx][ny] && !visited[nx][ny][turnOn]) {
visited[nx][ny][turnOn]=true;
if(key<turnOn) {
visited[x][y][turnOn] = true;
}
q.add(new int[] {nx,ny,turnOn});
}
} catch (Exception e) {
continue;
}
}
}
System.out.println(turnOn);
}
}
58 changes: 58 additions & 0 deletions baekjoon/14908_구두수선공/src/JIHANEOL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;


public class JIHANEOL {
static BufferedReader br;
static StringTokenizer st;
static class Work implements Comparable<Work>{
int no,t,s;

public Work(int no,int t, int s){
super();
this.no = no;
this.t = t;
this.s = s;
}
// 작업 , 보상금 으로 그리디 하게 접근 똑똑하다.
@Override
public int compareTo(Work o) {
double a = this.t/(double)this.s;
double b = (double)o.t/o.s;

if(a==b) {
return this.no - o.no;
}
return Double.compare(a, b);
}

}
static List<Work> list = new ArrayList();
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.valueOf(br.readLine());

for(int i=1; i<=N; i++) {
st = new StringTokenizer(br.readLine());
int t = Integer.valueOf(st.nextToken());
int s = Integer.valueOf(st.nextToken());
list.add(new Work(i,t, s));
}
Collections.sort(list);
StringBuilder sb = new StringBuilder();

for(Work w : list) {
sb.append(w.no + " ");
}
System.out.println(sb);

}

}
76 changes: 76 additions & 0 deletions baekjoon/8980_택배/src/JIHANEOL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import java.io.*;
import java.util.*;

// 머리가 좋아야한다. 초딩들 무야
public class JIHANEOL {
static BufferedReader br;
static StringTokenizer st;
static class Cupang implements Comparable<Cupang>{
int from,to,cost;

public Cupang(int from,int to, int cost) {
super();

this.from = from;
this.to = to;
this.cost = cost;
}

@Override
public int compareTo(Cupang o) {
return this.to == o.to ? Integer.compare(this.from, o.from) : Integer.compare(this.to, o.to);
}

}
public static int[] cp;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
int N = Integer.valueOf(st.nextToken());
int C = Integer.valueOf(st.nextToken());
cp = new int[N];
int total = 0;
int M = Integer.valueOf(br.readLine());
List<Cupang> list = new ArrayList();
Arrays.fill(cp,C);
for(int i=0; i<M; i++) {
st = new StringTokenizer(br.readLine());
int from = Integer.valueOf(st.nextToken());
int to = Integer.valueOf(st.nextToken());
int cost = Integer.valueOf(st.nextToken());
list.add(new Cupang(from, to , cost));
}
Collections.sort(list);

for(int i=0; i<M; i++) {
Cupang now = list.get(i);
int min = find(now.from,now.to);
// 양수면
if(min-now.cost>=0) {
total+=now.cost;
update(now.from, now.to, now.cost);
}else {
total+=min;
update(now.from, now.to, min);
}
}
System.out.println(total);

}
// 최소 찾기
static int find(int s, int e) {
int min = 10005;
for(int i=s; i<e; i++) {
if (cp[i]<min) {
min=cp[i];
}
}
return min;
}
// 갱신하기
static void update(int s, int e,int num) {
for(int i=s; i<e; i++) {
cp[i]-=num;
}
}
}
79 changes: 79 additions & 0 deletions programmers/섬연결하기/src/JIHANEOL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import java.util.Arrays;
import java.util.PriorityQueue;

class Node implements Comparable<Node>{
int from, to, cost;

Node(int f,int t, int c){
this.from = f;
this.to = t;
this.cost = c;
}

@Override
public int compareTo(Node o) {
// TODO Auto-generated method stub
return this.cost - o.cost;
}
}
public class JIHANEOL {
public static void main(String[] args) {

int n = 4;
int[][] costs = new int[][] {
{0,1,1},
{0,2,2},
{1,2,5},
{1,3,1},
{2,3,8}
};
Solution s = new Solution();
if (s.solution(n, costs)==4) {
System.out.println("정답");
} else {
System.out.println("땡");
}

}
}

class Solution {
int[] parents;

public int solution(int n, int[][] costs) {
int answer = 0;
PriorityQueue<Node> pq = new PriorityQueue<>();
// 진짜 바보다 n으로 해버렸네 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
for(int i =0; i<costs.length; i++){
pq.add(new Node(costs[i][0],costs[i][1],costs[i][2]));
}
parents = new int[n];
for(int i=0 ; i<n; i++){
parents[i] = i;
}
while(!pq.isEmpty()){
Node now = pq.poll();

if(union(now.from,now.to)){
answer+=now.cost;
}
}
return answer;
}
public boolean union(int x, int y){
if(find(x) == find(y)){
return false;
}else{
parents[find(y)] = find(x);
return true;
}
}
public int find(int x){
if(parents[x]==x){
return x;
}
return parents[x] = find(parents[x]);


}
}