Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
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
Archives
Today
Total
관리 메뉴

최's 먹공로그

SEA1493_수의 새로운 연산 본문

APS

SEA1493_수의 새로운 연산

ChoiSH313 2019. 3. 7. 08:42

https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV2b-QGqADMBBASw&categoryId=AV2b-QGqADMBBASw&categoryType=CODE

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Solution {
 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        // map에 값 미리 만들기
        int[][] map = new int[301][301];
        int number = 1;
        for (int i = 0; i <= 300; i++) {
            for (int j = i; j >= 0; j--) {
                map[i-j][j] = number++;
            }
        }
        
        int test_case = Integer.parseInt(br.readLine().trim());
        for (int tc = 1; tc <= test_case; tc++) {
            
            StringTokenizer st = new StringTokenizer(br.readLine().trim(), " ");
            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());
            int x_index = 0// 첫 숫자의 위치저장하기 위한 변수
            int y_index = 0;
            int x_index2 = 0// 두번째 숫자의 위치저장하기 위한 변수
            int y_index2 = 0;
            
            for (int i = 0; i <= 300; i++) {
                for (int j = 0; j <= 300; j++) {
                    if(map[i][j] == x) { // 첫 숫자 위치를 저장
                        x_index = i;
                        y_index = j;
                    }
                    if(map[i][j] == y) { // 두번째 숫자 위치를 저장
                        x_index2 = i;
                        y_index2 = j;
                    }
                }
            }
            // 계산
            int x_resultIndex = x_index + x_index2 + 1;
            int y_resultIndex = y_index + y_index2 + 1;
            
            System.out.println("#" + tc + " " + map[x_resultIndex][y_resultIndex]);
        } // end of tc
    }
}
 
cs

'APS' 카테고리의 다른 글

SEA7234_안전 기지(User Problem)  (2) 2019.03.07
SEA3752_가능한 시험점수  (0) 2019.03.07
SEA3459_승자예측하기  (0) 2019.03.06
백준3055_탈출  (0) 2019.03.06
SEA1257_[S/W 문제해결 응용] 6일차_K번째 문자열  (0) 2019.02.26