Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20240729 애쉬(박민아) - 2주차 #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
61 changes: 61 additions & 0 deletions boj/ashsty/week2/1461.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import java.util.*;
import java.io.*;

public class Main{

static int max=0;
static int n;
static int countPlus=0;
static int countMinus=0;
static int count = 0;
static List<Integer> plus;
static List<Integer> minus;

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

StringTokenizer str1 = new StringTokenizer(br.readLine());

int m = Integer.parseInt(str1.nextToken());
n = Integer.parseInt(str1.nextToken());

plus=new ArrayList<>();
minus=new ArrayList<>();

StringTokenizer str2 = new StringTokenizer(br.readLine());

for(int i=0; i<m; i++){
int num = Integer.parseInt(str2.nextToken());
max = Math.max(max, Math.abs(num));

if(num>=0){
plus.add(num);
}
else{
minus.add(Math.abs(num));
}
}

Collections.sort(plus);
Collections.sort(minus);

greedySejun(plus);
greedySejun(minus);

System.out.println(count - max);
}

private static void greedySejun(List<Integer> array){
int flag = array.size() % n;
int i = array.size() - 1;

while (i>flag-1){
count+=array.get(i)*2;
i-=n;
}

if(flag>0){
count+=array.get(i)*2;
}
}
}
49 changes: 49 additions & 0 deletions boj/ashsty/week2/1890.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.util.*;
import java.io.*;

public class Main{

static int max=0;
static int m;
static int n;
static int count = 0;
static int[][] map;
static long[][] check;

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

m = Integer.parseInt(br.readLine());

map = new int[m+1][m+1];
check = new long[m+1][m+1];

for(int i=1; i<=m; i++){
StringTokenizer str = new StringTokenizer(br.readLine());
for(int j=1; j<=m; j++){
map[i][j] = Integer.parseInt(str.nextToken());
}
}

check[1][1]=1;
dp(1, 1);

System.out.println(check[m][m]);
}

private static void dp(int startX, int startY){
int num=0;

for(int i=startX; i<=m;i++){
for(int j=startY; j<=m; j++){
num = map[i][j];
if(i+num<=m && num !=0){
check[i+num][j] +=check[i][j];
}
if(j+num<=m && num !=0){
check[i][j+num] +=check[i][j];
}
}
}
}
}
54 changes: 54 additions & 0 deletions boj/ashsty/week2/5567.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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));
StringTokenizer st;

int n = Integer.parseInt(br.readLine()); // 총 동기의 수
int m = Integer.parseInt(br.readLine()); // 친구 관계의 수

// 친구 관계를 저장할 인접 리스트
List<List<Integer>> friends = new ArrayList<>();
for (int i = 0; i <= n; i++) {
friends.add(new ArrayList<>());
}

// 친구 관계 입력 받기
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
friends.get(a).add(b);
friends.get(b).add(a);
}

// BFS를 위한 변수
boolean[] visited = new boolean[n + 1];
Queue<Integer> queue = new LinkedList<>();
int count = 0;
int level = 0;

// 상근이의 친구를 찾기 위한 BFS
visited[1] = true;
queue.add(1);

while (!queue.isEmpty() && level < 2) {
int size = queue.size();
for (int i = 0; i < size; i++) {
int current = queue.poll();
for (int friend : friends.get(current)) {
if (!visited[friend]) {
visited[friend] = true;
queue.add(friend);
count++;
}
}
}
level++;
}

System.out.println(count);
}
}
67 changes: 0 additions & 67 deletions boj/youngsu5582/week1/1260.java

This file was deleted.

43 changes: 0 additions & 43 deletions boj/youngsu5582/week1/2606.java

This file was deleted.

30 changes: 0 additions & 30 deletions boj/youngsu5582/week1/2839.java

This file was deleted.

37 changes: 0 additions & 37 deletions programmers/youngsu5582/178871.java

This file was deleted.