ํฐ์คํ ๋ฆฌ ๋ทฐ
Algorithm/Baekjoon
[Java] ๋ฐฑ์ค 14888๋ฒ - ์ฐ์ฐ์ ๋ผ์๋ฃ๊ธฐ
๊ฐ๋ฐ๊ฐ๊ตด๐ธ 2022. 6. 28. 21:42[๋ฌธ์ ]
[ํ์ด]
N๊ฐ์ ์์ ์์๋ ๊ณ ์ ์ด์ด์, ์ฌ์ด์ฌ์ด์ ์ฐ์ฐ์๋ฅผ ๋ฃ์ด ์กฐํฉํด ๊ณ์ฐํด์ฃผ๋ฉด ๋๋ ๋ฌธ์ ์์ต๋๋ค.
์ฐ์ number[]์ ์ซ์๋ฅผ ์ ์ฅํ๊ณ , operator[]์ ๊ฐ ์ฐ์ฐ๋ค์ ํค๊ฐ์ ๊ฐ์๋ฅผ ์ ์ฅํฉ๋๋ค.
๋ฐฑํธ๋ํน์ ์ด์ฉํ makeSet()๋ฅผ ํตํด 4์น ์ฐ์ฐ์ ์ํํ๋ฉฐ min๊ณผ max๊ฐ์ ๋ฝ์๋ด์ด ์ถ๋ ฅํฉ๋๋ค.
[์ฝ๋]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Main {
// ์ฐ์ฐ์ ๋ผ์๋ฃ๊ธฐ
public static int N;
public static int[] number;
public static int[] operator; // ์ฐ์ฐ์๋ค์ ํค๊ฐ์ ๋ฃ์ด์ค
public static int max = Integer.MIN_VALUE;
public static int min = Integer.MAX_VALUE;
public static ArrayList<String> setArr = new ArrayList<>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
number = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0;i<N;i++) {
number[i] = Integer.parseInt(st.nextToken());
}
operator = new int[4];
st = new StringTokenizer(br.readLine());
for(int i=0;i<4;i++) {
operator[i] = Integer.parseInt(st.nextToken());
}
makeSet(number[0],1);
System.out.println(max);
System.out.println(min);
}
public static void makeSet(int num, int index) {
if(index == N) {
max = Math.max(max, num);
min = Math.min(min, num);
return;
}
for(int i=0;i<4;i++) {
if(operator[i] > 0) {
operator[i]--;
switch (i){
case 0:
makeSet(num + number[index],index + 1);
break;
case 1:
makeSet(num - number[index],index + 1);
break;
case 2:
makeSet(num * number[index],index + 1);
break;
case 3:
makeSet(num / number[index],index + 1);
break;
}
operator[i]++;
}
}
}
}
'Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] ๋ฐฑ์ค 7453๋ฒ - ํฉ์ด 0์ธ ๋ค ์ ์ (0) | 2022.06.28 |
---|---|
[Java] ๋ฐฑ์ค 9466๋ฒ - ํ ํ๋ก์ ํธ (0) | 2022.06.28 |
[Java] ๋ฐฑ์ค 1939๋ฒ - ์ค๋์ ํ (0) | 2022.06.13 |
[Java] ๋ฐฑ์ค 1931๋ฒ - ํ์์ค ๋ฐฐ์ (0) | 2022.06.13 |
[Java] ๋ฐฑ์ค 2461๋ฒ - ๋ํ ์ ์ (0) | 2022.06.05 |
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- ๋ฐฑ์ค node.js
- ๋ฐฑ์ค javascript
- ํ๋กํผํฐ
- ๋ ์์ปฌ ํ๊ฒฝ
- 2019 ์นด์นด์ค ๊ฐ๋ฐ์ ๊ฒจ์ธ ์ธํด
- ์๋ฐ
- git
- JavaScript
- ์๊ณ ๋ฆฌ์ฆ
- ๋ค์ด๋๋ฏน ํ๋ก๊ทธ๋๋ฐ
- ์นด์นด์ค ์ธํด
- ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ
- ํจ์ํ ํ๋ก๊ทธ๋๋ฐ
- ์ฝ๋ฉํ ์คํธ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ์ ์ญ ๋ณ์
- ํฌํฌ์ธํฐ
- fp
- http
- map
- Baekjoon
- ํ๋ก๊ทธ๋๋จธ์ค
- ๋์์ธ ํจํด
- ๋ชจ๋ ์๋ฐ์คํฌ๋ฆฝํธ deep dive
- ์ด์์ฒด์
- ๋ฐฑ์ค
- ๋คํธ์ํฌ
- ํ๋กํ ์ฝ
- TDD
- ์ด๋ถํ์
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
๊ธ ๋ณด๊ดํจ