ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • SWEA 5658 [보물상자 비밀번호]
    알고리즘 풀이/시뮬레이션 2018. 9. 22. 09:24

    SW Expert Academy 보물상자 비밀번호 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRUN9KfZ8DFAUo&categoryId=AWXRUN9KfZ8DFAUo&categoryType=CODE



    //SWEA는 문제를 무단으로 복제하는 것을 금지하기에, 자세하게 설명하지 않습니다.




    안녕하세요. 이번 문제는 SW Expert Academy의 보물상자 비밀번호 입니다.


    회전하면서 나올 수 있는 모든 정수를 따져서 정렬하는 문제입니다.


    회전하면서 나올 정수를 그냥 HashMap에 때려박았습니다.


    HashMap의 키값을 불러와 ArrayList에 저장한 뒤, 정렬하여 요구하는 K번째의 수를 찾아냈습니다.







    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
    import java.util.*;
    public class Solution {
        public static int T;
        public static int N, K;
        public static int capacity;    //한 변의 길이 :N / 4
        
        public static char[] password = new char[28];
        public static HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        public static ArrayList<Integer> list = new ArrayList<Integer>();
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int T = sc.nextInt();
            for(int test_case = 1; test_case <= T; test_case++) {
                N = sc.nextInt();
                K = sc.nextInt();
                String str = sc.next();
                for(int i = 0; i < N; i++
                    password[i] = str.charAt(i);
                capacity =/ 4;
                
                for(int i = 0; i < capacity ; i++ ) {    //회전 하는동안 나올 수 
                    for(int j = 0; j < 4; j++) {
                        int num = 0;
                        for(int k = 0; k < capacity; k++) {
                            int temp = 0;
                            if(password[capacity * j + k] <= 57) temp = (int)password[capacity * j + k] - 48;
                            else temp = (int)password[capacity*+ k] - 55;
                            num += (int)Math.pow(16, capacity - 1 - k) * temp; 
                        }
                        map.put(num, 1);
                    }
                    char temp = password[N-1];
                    for(int j = N-1; j > 0; j--) {
                        password[j] = password[j-1];
                    }
                    password[0= temp;
                }
                Set set = map.keySet();
                Iterator it= set.iterator();
                
                while(it.hasNext()) {
                    list.add((int)it.next());
                }
                Collections.sort(list);
                System.out.println("#" + test_case + " " + list.get(list.size()-K));
                list.clear();
                map.clear();
            }
        }
    }
    cs


    반응형

    '알고리즘 풀이 > 시뮬레이션' 카테고리의 다른 글

    SWEA 5644 [무선 충전]  (2) 2018.10.04
    SWEA 5650 [핀볼 게임]  (0) 2018.09.25
    SWEA 5656 [벽돌 깨기]  (2) 2018.09.22
    BOJ 15685 [드래곤 커브]  (3) 2018.09.17

    댓글

Designed by Tistory.