SWEA1208 Flatten
ํจ์จ์ ์ผ๋ก ๊ณ์ฐํ๋ ๋ฐฉ๋ฒ์ ์ฝ์ง ์๊ฒ ์ง๋ง, ๋ฌธ์ ์์ ์ฃผ์ด์ง ์คํ์๊ฐ์ด 20์ด์ด๊ธฐ ๋๋ฌธ์ ๋จ์ํ๊ฒ MAX, MIN์ ์ฐพ์ ๊ตฌํํ๋ฉด ๋๋ค.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
class Solution {
static BufferedReader br;
static BufferedWriter bw;
static StringTokenizer st;
static int[] Box;
static int numofBox;
static void dump() {
int[] m_idx = search_MaxnMin();
Box[m_idx[0]]--;
Box[m_idx[1]]++;
}
static int[] search_MaxnMin() {
int max = Box[0], min = Box[0];
int max_idx = 0, min_idx = 0;
for (int i = 1; i < numofBox; i++) {
if (max < Box[i]) {
max_idx = i;
max = Box[i];
}
if (min > Box[i]) {
min_idx = i;
min = Box[i];
}}
int[] r = { max_idx, min_idx };
return r;
}
public static void main(String args[]) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
bw = new BufferedWriter(new OutputStreamWriter(System.out));
int T = 10;
for (int tc = 1; tc <= T; tc++) {
int N = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine(), " ");
numofBox = st.countTokens();
Box = new int[numofBox];
for (int i = 0; i < numofBox; i++) {
Box[i] = Integer.parseInt(st.nextToken());
}
for (int i = 0; i < N; i++) {
dump();
}
int[] m_idx = search_MaxnMin();
int dif = Box[m_idx[0]] - Box[m_idx[1]];
//System.out.println(dif);
bw.write(String.format("#%d ", tc)); bw.write(String.format("%d\n", dif));
}
bw.flush();
bw.close();
}
}
Author And Source
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(SWEA1208 Flatten), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://velog.io/@mraz0210/SWEA1208-Flatten์ ์ ๊ท์: ์์์ ์ ๋ณด๊ฐ ์์์ URL์ ํฌํจ๋์ด ์์ผ๋ฉฐ ์ ์๊ถ์ ์์์ ์์ ์ ๋๋ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ
์ธ ๋ฐ๊ฒฌ์ ์ ๋
(Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค