-
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
Showing
3 changed files
with
101 additions
and
3 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 |
---|---|---|
@@ -1,2 +1,59 @@ | ||
package PACKAGE_NAME;public class Main { | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Main { | ||
|
||
static List<Integer> lis = new ArrayList<>(); | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); | ||
int n = Integer.parseInt(bf.readLine()); | ||
int[] arr = new int[n]; | ||
int[] index = new int[n]; | ||
|
||
StringTokenizer st = new StringTokenizer(bf.readLine()); | ||
for(int i = 0; i < n; i++) { | ||
arr[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
lis.add(arr[0]); | ||
index[0] = 0; | ||
for(int i = 1; i < n; i++) { | ||
int last = lis.get(lis.size() - 1); | ||
if(arr[i] > last) { | ||
lis.add(arr[i]); | ||
index[i] = lis.size() - 1; | ||
} else { | ||
int idx = binarySearch(0, lis.size() - 1, arr[i]); | ||
lis.set(idx, arr[i]); | ||
index[i] = idx; | ||
} | ||
} | ||
|
||
System.out.println(lis.size()); | ||
int count = lis.size() - 1; | ||
List<Integer> result = new ArrayList<>(); | ||
for(int i = n - 1; i >= 0; i--) { | ||
if(count == index[i]) { | ||
result.add(arr[i]); | ||
count --; | ||
} | ||
} | ||
|
||
for(int i = result.size() - 1; i >= 0; i --) { | ||
System.out.print(result.get(i) + " "); | ||
} | ||
} | ||
|
||
public static int binarySearch(int start, int end, int des) { | ||
if(start >= end) { | ||
return start; | ||
} | ||
int mid = (start + end) / 2; | ||
|
||
if(lis.get(mid) >= des) { | ||
return binarySearch(start, mid, des); | ||
} else { | ||
return binarySearch(mid + 1, end, des); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,27 @@ | ||
package PACKAGE_NAME;public class Main { | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); | ||
String str1 = bf.readLine(); | ||
String str2 = bf.readLine(); | ||
|
||
int[][] dp = new int[str1.length() + 1][str2.length() + 1]; | ||
for(int i = 1; i <= str1.length(); i++) { | ||
for(int j = 1; j <= str2.length(); j++) { | ||
if(str1.charAt(i - 1) == str2.charAt(j - 1)) { | ||
|
||
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]) + 1; | ||
} else { | ||
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); | ||
} | ||
System.out.print(dp[i][j] + " "); | ||
} | ||
System.out.println(); | ||
} | ||
System.out.println(dp[str1.length()][str2.length()]); | ||
|
||
for(int i = str1.length()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,18 @@ | ||
package PACKAGE_NAME;public class Main { | ||
import java.util.*; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Set<Integer> hits = new HashSet<>(); | ||
Random random = new Random(); | ||
|
||
// 6개의 숫자를 중복 없이 뽑기 | ||
while (hits.size() < 6) { | ||
int number = random.nextInt(45) + 1; // 1부터 45까지의 숫자 | ||
hits.add(number); | ||
} | ||
|
||
// 결과 출력 | ||
System.out.println("당첨 숫자: " + hits.stream().sorted().toList()); | ||
} | ||
} |