Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c97a905
Merge pull request #26 from Summer2024-PS-Study/hyohwan
Seoyoung2222 Jul 21, 2024
59b4bba
박서영 3주차 과제 제출 - 11561
Seoyoung2222 Jul 21, 2024
48d05f2
Merge pull request #27 from Seoyoung2222/main
Seoyoung2222 Jul 21, 2024
9e80cea
Merge pull request #28 from Summer2024-PS-Study/seoyoung
Seoyoung2222 Jul 21, 2024
a3665a2
Merge pull request #2 from Summer2024-PS-Study/main
clwmfksek Jul 21, 2024
148f655
신효환 3주차 과제 제출 - 1590
clwmfksek Jul 21, 2024
7b3b35b
Merge pull request #29 from clwmfksek/main
clwmfksek Jul 21, 2024
5531930
Merge pull request #1 from Summer2024-PS-Study/main
Seoyoung2222 Jul 23, 2024
e4b6c51
박서영 3주차 과제 제출 - 1939 (메모리 초과)
Seoyoung2222 Jul 23, 2024
8112b9b
박서영 3주차 과제 - 1939 (메모리 초과)
Seoyoung2222 Jul 23, 2024
ed120fd
Merge pull request #30 from Seoyoung2222/main
Seoyoung2222 Jul 23, 2024
f61ad50
Merge pull request #31 from Summer2024-PS-Study/seoyoung
Seoyoung2222 Jul 23, 2024
bd93a6c
4주차 과제 제출 모듈 생성
Seoyoung2222 Jul 23, 2024
2c5c672
Merge pull request #32 from Seoyoung2222/main
Seoyoung2222 Jul 23, 2024
a7ebc50
Merge pull request #33 from Summer2024-PS-Study/seoyoung
Seoyoung2222 Jul 23, 2024
eff008b
박서영 4주차 과제 제출 - 28357(런타임에러)
Seoyoung2222 Jul 27, 2024
c2de2d6
Merge pull request #34 from Seoyoung2222/main
Seoyoung2222 Jul 27, 2024
464e618
Merge pull request #35 from Summer2024-PS-Study/seoyoung
Seoyoung2222 Jul 27, 2024
dd83e32
박서영 4주차 과제 제출 - 2992
Seoyoung2222 Jul 28, 2024
0f8b798
Merge pull request #37 from Seoyoung2222/main
Seoyoung2222 Jul 28, 2024
add9e61
Merge pull request #38 from Summer2024-PS-Study/seoyoung
Seoyoung2222 Jul 28, 2024
af5d2bd
Merge pull request #3 from Summer2024-PS-Study/main
clwmfksek Jul 29, 2024
6be753a
신효환 4주차 과제 제출 - 6603
clwmfksek Jul 29, 2024
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
38 changes: 38 additions & 0 deletions week3/src/psy_11561.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.Scanner;

public class psy_11561 {
public static long start = 0;
public static long end = 141421356; // 밟을 수 있는 최대 횟수 지정

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
long[] N = new long[T];

// 징검다리 수 저장
for (int i = 0; i < T; i++) {
N[i] = sc.nextLong();
}

for (int i = 0; i < T; i++) {
System.out.println(binSearch(N[i], start, end));
}
}

// 밟은 횟수를 기준으로 이진 탐색 진행
private static long binSearch(long N, long start, long end) {
long mid = (start + end) / 2;

// 등차수열의 합 법칙으로 최대로 밟을 수 있는 횟수 찾기
while (start <= end) {
mid = (start + end) / 2;
if ((mid * (mid + 1) / 2) <= N) {
start = mid + 1;
} else {
end = mid - 1;
}
}
return end;
}
}

72 changes: 72 additions & 0 deletions week3/src/psy_1939.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class psy_1939 {
public static int[][] arr;
public static int N;
private static boolean[] visited;
private static List<List<Integer>> allPaths = new ArrayList<>();
private static int max_weight = 0;

static class Graph {
public Graph(int N) {
arr = new int[N+1][N+1];
}

public List<List<Integer>> findAllPath(int start, int end) {
boolean[] visited = new boolean[N+1];
List<Integer> currentPath = new ArrayList<>();
search(start, end, visited, currentPath, allPaths);
return allPaths;
}

public static void search(int current, int end, boolean[] visited, List<Integer> currentPath, List<List<Integer>> allPaths) {
visited[current] = true;
currentPath.add(current);

if (current == end) {
allPaths.add(new ArrayList<>(currentPath));
} else {
for (int neighbor = 1; neighbor <= N; neighbor++) {
if (arr[current][neighbor] != 0 && !visited[neighbor]) {
search(neighbor, end, visited, currentPath, allPaths);
if (max_weight < arr[current][neighbor])
max_weight = arr[current][neighbor];
}
}
}

// Backtrack
visited[current] = false;
currentPath.remove(currentPath.size() - 1);
}
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] token = br.readLine().split(" ");
N = Integer.parseInt(token[0]);
int M = Integer.parseInt(token[1]);

Graph graph = new Graph(N);
arr = new int[N+1][N+1];

for (int i = 0; i < M; i++) {
token = br.readLine().split(" ");
arr[Integer.parseInt(token[0])][Integer.parseInt(token[1])] = Integer.parseInt(token[2]);
arr[Integer.parseInt(token[1])][Integer.parseInt(token[0])] = Integer.parseInt(token[2]);
}

token = br.readLine().split(" ");
int DP = Integer.parseInt(token[0]);
int AP = Integer.parseInt(token[1]);

List<List<Integer>> allPaths = graph.findAllPath(AP, DP);

System.out.println(max_weight);
}
}

50 changes: 50 additions & 0 deletions week3/src/shh_1590.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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

int N = Integer.parseInt(st.nextToken());
int T = Integer.parseInt(st.nextToken());

int minvalue = Integer.MAX_VALUE;

for (int j = 0; j < N; j++) {
st = new StringTokenizer(br.readLine());
int S = Integer.parseInt(st.nextToken());
int I = Integer.parseInt(st.nextToken());
int C = Integer.parseInt(st.nextToken());

if (S + I * (C - 1) < T) continue;

int start = 0;
int end = C - 1;
int ans = Integer.MAX_VALUE;

while (start <= end) {
int mid = (start + end) / 2;
int currentValue = S + I * mid;

if (currentValue >= T) {
ans = currentValue;
end = mid - 1;
} else {
start = mid + 1;
}
}
if (ans != Integer.MAX_VALUE) {
minvalue = Math.min(minvalue, ans - T);
}
}

if (minvalue == Integer.MAX_VALUE) {
System.out.println(-1);
} else {
System.out.println(minvalue);
}
}
}
32 changes: 32 additions & 0 deletions week3/src/shh_17204.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class shh_17204 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String[] strArr = br.readLine().split(" ");
int n = Integer.parseInt(strArr[0]);
int k = Integer.parseInt(strArr[1]);

int[] lis = new int[n];
for(int i=0; i<n;i++){
int num1 = Integer.parseInt(br.readLine());
lis[i] = num1;
}
Boolean bol = false;
int count = 0;
int target = 0;

for(int i=0; i<n;i++){
target = lis[target];
count += 1;
if(target==k){
bol = true;
break;
}
}
if(bol) System.out.println(count);
else System.out.println(-1);
}
}
47 changes: 47 additions & 0 deletions week4/src/psy_28357.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class psy_28357 {
public static long[] students;

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

int N = Integer.parseInt(token[0]);
long K = Long.parseLong(token[1]);
students = new long[N];

token = br.readLine().split(" ");
for (int i = 0; i < N; i++) {
students[i] = Integer.parseInt(token[i]);
}

System.out.println(binSearch(0,100,K)); // 0점에서 100점 사이에서 선택
}

public static long binSearch(long start, long end, long key) {
long result = 0;
while (start <= end) {
long mid = (start + end) / 2;
long candies = candy(mid);
if (candies >= key) {
result = mid;
start = mid + 1;
} else {
end = mid - 1;
}
}
return result;
}

public static long candy(long mid) {
long result = 0;
for (int i = 0; i < students.length; i++) {
if (students[i]-mid > 0)
result += students[i]-mid;
}
return result;
}
}
75 changes: 75 additions & 0 deletions week4/src/psy_2992.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import java.util.Scanner;

public class psy_2992 {
public static int result; // 결과값을 저장하는 변수

// 다음 순열을 찾는 함수
public static int nextPermutation(int[] nums, int N, int digits) {
int pivot = digits - 2;

// 뒤에서부터 첫 번째 감소하는 요소를 찾음
while (pivot >= 0 && nums[pivot] >= nums[pivot + 1]) {
pivot--;
}

if (pivot >= 0) {
// 뒤에서부터 계산하여 처음으로 내림이 되는 경우 찾기 (두 수의 자리를 바꿨을 때 숫자가 커지는 첫 지점)
for (int i = digits - 1; i > pivot; i--) {
if (nums[i] > nums[pivot]) {
swap(nums, pivot, i); // 피벗과 i 위치의 요소를 교환
break;
}
}
} else { // 전체가 내림차순인 경우
return 0;
}

// 피벗 이후 부분을 반전시켜서 가장 작게 만들기
reverse(nums, pivot + 1, digits - 1);

result = 0;
// 결과가 N보다 크거나, 결과가 0으로 시작하지 않는 경우에만 결과값 계산
if (result > N || nums[0] != 0) {
for (int i = 0; i < digits; i++) {
result = result * 10 + nums[i];
}
}

return result;
}

// 두 요소의 위치를 교환하는 함수
private static void swap(int[] nums, int i, int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}

// 주어진 범위의 배열을 반전시키는 함수
private static void reverse(int[] nums, int start, int end) {
while (start < end) {
swap(nums, start, end);
start++;
end--;
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int digits = (int) Math.log10(Math.abs(N)) + 1; // 숫자의 자릿수 계산
int[] nums = new int[digits];

if (digits != 1) { // 자릿수가 1이 아닌 경우
int n = N;
for (int i = 0; i < digits; i++) { // 각 자릿수를 배열에 저장
nums[i] = (int) (n / Math.pow(10, digits - (i + 1)));
n = (int) (n - nums[i] * Math.pow(10, digits - (i + 1)));
}
}

nextPermutation(nums, N, digits);
System.out.println(result);
}
}

40 changes: 40 additions & 0 deletions week4/src/shh_6603_java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.*;
import java.util.*;

public class Main {
void bt(int start, ArrayList<Integer> arr, LinkedList<Integer> result, int n) {
if (result.size() == 6) {
for (int num : result) {
System.out.print(num + " ");
}
System.out.println();
return;
}

for (int i = start; i < n; i++) {
result.add(arr.get(i));
bt(i + 1, arr, result, n);
result.removeLast();
}
}

public static void main(String[] args) throws IOException {
Main main = new Main();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line);
int n = Integer.parseInt(st.nextToken());
if (n == 0) break;

ArrayList<Integer> arr = new ArrayList<>();
for (int i = 0; i < n; i++) {
arr.add(Integer.valueOf(st.nextToken()));
}

LinkedList<Integer> res = new LinkedList<>();
main.bt(0, arr, res, n);
System.out.println();
}
}
}
11 changes: 11 additions & 0 deletions week4/week4.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>