-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from hgene0929/main
이현진 / 11월 1주차 / 목
- Loading branch information
Showing
3 changed files
with
160 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class boj14226_이모티콘 { | ||
static int S; | ||
|
||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
// input | ||
S = Integer.parseInt(br.readLine()); | ||
|
||
// solution | ||
int res = bfs(); | ||
|
||
// output | ||
System.out.println(res); | ||
} | ||
|
||
static int bfs() { | ||
Queue<int[]> queue = new ArrayDeque<>(); | ||
int[][] dp = new int[2*S+1][S+1]; // 문자열길이, 클립보드길이 = 시간 | ||
queue.offer(new int[] { 1,0,0 }); // 문자열길이, 클립보드길이, 시간 | ||
for(int i=0; i<=S; i++) Arrays.fill(dp[i], Integer.MAX_VALUE); | ||
|
||
while(!queue.isEmpty()) { | ||
int[] now = queue.poll(); | ||
if(now[2] < dp[now[0]][now[1]]) { | ||
dp[now[0]][now[1]] = now[2]; | ||
queue.offer(new int[] { now[0],now[0],now[2]+1 }); | ||
if(now[1] != 0) queue.offer(new int[] { now[0]+now[1],now[1],now[2]+1 }); | ||
if(now[0]-1 > 0) queue.offer(new int[] { now[0]-1,now[1],now[2]+1 }); | ||
} | ||
} | ||
|
||
return getMin(dp); | ||
} | ||
|
||
static int getMin(int[][] dp) { | ||
int min = Integer.MAX_VALUE; | ||
for(int time : dp[S]) { | ||
min = Math.min(min, time); | ||
} | ||
return min; | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class boj23829_인문예술탐사주간 { | ||
static int N, Q; | ||
static int[] p, x; | ||
static long[] sumDistFromZero; | ||
|
||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
// input | ||
StringTokenizer st = new StringTokenizer(br.readLine(), " "); | ||
N = Integer.parseInt(st.nextToken()); | ||
Q = Integer.parseInt(st.nextToken()); | ||
sumDistFromZero = new long[N+1]; | ||
p = new int[N]; | ||
x = new int[Q]; | ||
|
||
st = new StringTokenizer(br.readLine(), " "); | ||
for(int i=0; i<N; i++) p[i] = Integer.parseInt(st.nextToken()); | ||
Arrays.sort(p); | ||
sumDistFromZero[1] = p[0]; | ||
for(int i=2; i<=N; i++) sumDistFromZero[i] = sumDistFromZero[i-1] + p[i-1]; | ||
for(int i=0; i<Q; i++) x[i] = Integer.parseInt(br.readLine()); | ||
|
||
// solution | ||
StringBuilder sb = new StringBuilder(); | ||
for(int pic : x) { | ||
// 1. 나무들 사이의 사진의 인덱스 구하기(사진위치보다 크거나 같은 첫번째 나무 인덱스) | ||
int idx = lowerBound(0, N-1, pic); | ||
// 2. pic 인덱스를 기준으로 각각 오른쪽, 왼쪽에 있는 나무들과의 거리합 구하기 | ||
sb.append(getSumDistBtw(idx, pic)).append("\n"); | ||
} | ||
|
||
// output | ||
System.out.println(sb.toString()); | ||
} | ||
|
||
static int lowerBound(int left, int right, int target) { | ||
while(left < right) { | ||
int mid = (left+right)/2; | ||
if(p[mid] >= target) { | ||
right = mid; | ||
} else { | ||
left = mid+1; | ||
} | ||
} | ||
return right; | ||
} | ||
|
||
static long getSumDistBtw(int idx, int pic) { | ||
if(pic > p[N-1]) { | ||
return Math.abs(sumDistFromZero[N] - (long)pic *N); | ||
} | ||
int cntL = idx, cntR = N-idx; | ||
long sum = 0; | ||
sum += Math.abs(sumDistFromZero[idx] - (long)pic *cntL); | ||
sum += sumDistFromZero[N] - sumDistFromZero[idx] - (long)pic *cntR; | ||
return sum; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class boj25795_예쁜초콜릿과숫자놀이 { | ||
static int N, a, b, c; | ||
static char[] chocolates; | ||
static final int MOD = 100000, WHITE = 1, DARK = -1; | ||
static long res = Integer.MIN_VALUE; | ||
|
||
public static void main(String[] args) throws Exception { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
// input | ||
StringTokenizer st = new StringTokenizer(br.readLine(), " "); | ||
N = Integer.parseInt(st.nextToken()); | ||
a = Integer.parseInt(st.nextToken()); | ||
b = Integer.parseInt(st.nextToken()); | ||
c = Integer.parseInt(st.nextToken()); | ||
|
||
// solution | ||
chocolates = new char[2*N]; | ||
construct(0, N, 0); | ||
|
||
// output | ||
System.out.println(res); | ||
} | ||
|
||
static void construct(int prev, int cntW, int idx) { | ||
if(idx == 2*N) { | ||
res = Math.max(res, calc()); | ||
return; | ||
} | ||
if(prev > 0) { | ||
chocolates[idx] = 'D'; | ||
construct(prev+DARK, cntW, idx+1); | ||
} | ||
if(cntW > 0) { | ||
chocolates[idx] = 'W'; | ||
construct(prev+WHITE, cntW-1, idx+1); | ||
} | ||
} | ||
|
||
static long calc() { | ||
long sum = a; | ||
for(char chocolate : chocolates) { | ||
if(chocolate == 'W') sum = (sum+b)%MOD; | ||
else sum = (sum*c)%MOD; | ||
} | ||
return sum; | ||
} | ||
} |