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

이태호 / 11월 2주차 / 월, 목 #327

Open
wants to merge 4 commits 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
40 changes: 40 additions & 0 deletions LeeTaeHo/boj/boj11037.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.*;
import java.util.*;

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

StringBuilder sb = new StringBuilder();
String s = "";
while((s = br.readLine()) != null){
int n = Integer.parseInt(s);
int result = 0;
while(++n <= 999_999_999){
if(isDuplicate(n)){
result = n;
break;
}

}
sb.append(result).append("\n");
}
System.out.println(sb);
}

static boolean isDuplicate(int n){
Arrays.fill(visited, false);
while(n > 0){
int digit = n % 10;
if(digit == 0) return false;
if(visited[digit]){
return false;
}else{
visited[digit] = true;
}
n /= 10;
}
return true;
}
}
56 changes: 56 additions & 0 deletions LeeTaeHo/boj/boj14226.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import java.io.*;
import java.util.*;

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

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

System.out.println(getEmoticons(s));
}

static int getEmoticons(int s){
boolean[][] visited = new boolean[1004][1004];
Queue<Node> q = new LinkedList<>();
q.offer(new Node(1, 0, 0));
visited[1][0] = true;
while(!q.isEmpty()){
Node node = q.poll();

int cnt = node.cnt;
int buffer = node.buffer;
int time = node.time;

if(cnt == s) return time;

if(cnt - 1 >= 0 && !visited[cnt - 1][buffer]){
visited[cnt - 1][buffer] = true;
q.offer(new Node(cnt - 1, buffer, time + 1));
}

if(buffer + cnt <= 1000 && !visited[cnt][cnt]){
visited[cnt][cnt] = true;
q.offer(new Node(cnt, cnt, time + 1));
}

if(buffer != 0 && cnt + buffer <= 1000 && !visited[cnt + buffer][buffer]){
visited[cnt + buffer][buffer] = true;
q.offer(new Node(cnt + buffer, buffer, time + 1));
}
}
return 0;
}

static class Node{
int cnt;
int buffer;
int time;

public Node(int cnt, int buffer, int time) {
this.cnt = cnt;
this.buffer = buffer;
this.time = time;
}
}
}
52 changes: 52 additions & 0 deletions LeeTaeHo/boj/boj23829.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.io.*;
import java.util.*;

public class boj23829 {
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 q = Integer.parseInt(st.nextToken());

int[] arr = new int[n];
long[] prefix = new long[n + 1];

st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}

Arrays.sort(arr);

for (int i = 0; i < n; i++) {
prefix[i + 1] = prefix[i] + arr[i];
}

StringBuilder sb = new StringBuilder();

for (int i = 0; i < q; i++) {
int p = Integer.parseInt(br.readLine());
int idx = binarySearch(arr, p);

sb.append((prefix[n] - prefix[idx] - ((long) p * (n - idx))) + (Math.abs(prefix[idx] - ((long) p * idx)))).append("\n");
}
System.out.println(sb);
}

static int binarySearch(int[] arr, int p){
int left = 0;
int right = arr.length;

while(left < right){
int mid = (left + right) / 2;

if(arr[mid] < p){
left = mid + 1;
}else{
right = mid;
}
}
return right;
}
}
36 changes: 36 additions & 0 deletions LeeTaeHo/boj/boj25795.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.io.*;
import java.util.*;

public class boj25795 {
static final int MOD = 100000;
static int n, b, c;
static long max;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

n = Integer.parseInt(st.nextToken());
int a = Integer.parseInt(st.nextToken());
b = Integer.parseInt(st.nextToken());
c = Integer.parseInt(st.nextToken());

max = 0;

dfs(a + b,1, 0, 1);
System.out.println(max);
}

static void dfs(long result, int white, int dark, int depth){
if(depth == n + n){
if(result > max ) max = result;
return;
}

if(white != n){
dfs((result + b) % MOD, white + 1, dark, depth + 1);
}
if(white > dark && dark != n){
dfs((result * c) % MOD, white, dark + 1, depth + 1);
}
}
}
Loading