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
 
public class Main {
 
    //3 16
    //result
    //3
    //5
    //7
    //11
    //13
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str);
        int start = Integer.parseInt(st.nextToken());
        int end = Integer.parseInt(st.nextToken());
        
        boolean[] bool = new boolean[end + 1];
        for(int i = 2; i < bool.length; i++) {
            bool[i] = true;
        }
        
        for(int i = 2; i < Math.sqrt(bool.length); i++) {
            if(bool[i]) {
                for(int j = i * i; j < bool.length; j += i) {
                    bool[j] = false;
                }
            }
        }
        
        for(int i = start; i <= end; i++) {
            if(bool[i]) bw.write(String.valueOf(i) + "\n");
        }
        bw.flush();
        
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'알고리즘' 카테고리의 다른 글

백준 9단계(9020)  (0) 2019.12.22
백준 9단계(4948)  (0) 2019.12.22
백준 9단계(2581)  (0) 2019.12.22
백준 9단계(1978)  (0) 2019.12.21
백준 8단계(1011)  (0) 2019.12.21
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
52
53
54
55
56
 
public class Main {
    
    //60
    //100
    //result 
    //620
    //61
    
    //64
    //65
    //result
    //-1
    //sieve of eratosthenes algo
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int start = Integer.parseInt(br.readLine().trim());
        int end = Integer.parseInt(br.readLine().trim());
        //에라토스테네스의 체
        boolean[] bool = new boolean[end + 1];
        
        for(int i = 2; i < bool.length; i++) {
            bool[i] = true;
        }
        
        for(int i = 2; i < Math.sqrt(bool.length); i++) {
            if(bool[i]) {
                for(int j = i * i; j < bool.length; j += i) {
                    bool[j] = false;
                }
            }
        }
        
        int sum = 0;
        int min = 10000;
        boolean print = false;
        for(int i = start; i <= end; i++) {
            if(bool[i]) {
                print = true;
                sum += i;
                if(min > i) min = i;
            }
        }
        
        if(printbw.write(String.valueOf(sum) + "\n" + min);
        else bw.write("-1");
        bw.flush();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'알고리즘' 카테고리의 다른 글

백준 9단계(4948)  (0) 2019.12.22
백준 9단계(1929)  (0) 2019.12.22
백준 9단계(1978)  (0) 2019.12.21
백준 8단계(1011)  (0) 2019.12.21
백준 8단계(2775)  (0) 2019.12.15
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
 
public class Main {
 
    //just regular method
//    public static void main(String[] args) throws Exception{
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        
//        int n = Integer.parseInt(br.readLine());
//        String str = br.readLine();
//        StringTokenizer st = new StringTokenizer(str);
//        int cnt = 0;
//        
//        while(st.hasMoreTokens()) {
//            int a = Integer.parseInt(st.nextToken());
//            
//            //1은 false로 소수처리, 나머지는 확인 전이니 true
//            boolean flag = (a == 1)? false : true;
//            for(int i = 2; i < a; i++) {
//                //만약 나머지가 있다는 뜻은 소수가 아니란 뜻이므로 false가 for문 break;
//                if(a % i == 0) {
//                    flag = false;
//                    break;
//                }
//            }
//            
//            if(flag) cnt++;
//        }
//        bw.flush();
//        
//    }
    
    //4
    //1 3 5 7
    
    //result
    //3
    
    //sieve of eratosthenes 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str);
        
        boolean[] bool = new boolean[1001];
        
        for(int i = 2; i < bool.length; i++) {
            bool[i] = true;
        }
        
        for(int i = 2; i < Math.sqrt(bool.length); i++) {
            if(bool[i]) {
                for(int j = i * i; j < bool.length; j += i) {
                    bool[j] = false;
                }
            }
        }
        
        int cnt = 0;
        while(st.hasMoreTokens()) {
            int number = Integer.parseInt(st.nextToken());
            if(bool[number]) cnt++;
        }
        
        bw.write(String.valueOf(cnt));
        bw.flush();
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

if문에 (bool[i] = true)를 주면 해당 값을 true로 변환... 근데 또 while문안에 있는 if문이면 그냥 조건으로 인식...

9020이랑 똑같은 방식으로 풀었지만 여기선 true로 변환

'알고리즘' 카테고리의 다른 글

백준 9단계(1929)  (0) 2019.12.22
백준 9단계(2581)  (0) 2019.12.22
백준 8단계(1011)  (0) 2019.12.21
백준 8단계(2775)  (0) 2019.12.15
백준 8단계(10250)  (0) 2019.12.15
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
 
public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int n = Integer.parseInt(br.readLine());
        while(n > 0) {
            String str = br.readLine();
            StringTokenizer st = new StringTokenizer(str);
            long start = Integer.parseInt(st.nextToken());
            long end = Integer.parseInt(st.nextToken());
            
            long length = 0;
            int cnt = 0;
            //앞에선 더해주고, 뒤해선 빼주는식으로 구현
            //start가 end와 같거나 크면 종료
            while(start < end) {
                length++;
                start += length;
                cnt++;
                
                if(start >= end) {
                    break;
                }
                
                end -= length;
                cnt++;
                
                if(start >= end) {
                    break;
                }
            }
            
            bw.write(String.valueOf(cnt) + "\n");
            n--;
        }
        bw.flush();
                
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'알고리즘' 카테고리의 다른 글

백준 9단계(2581)  (0) 2019.12.22
백준 9단계(1978)  (0) 2019.12.21
백준 8단계(2775)  (0) 2019.12.15
백준 8단계(10250)  (0) 2019.12.15
백준 8단계(2869)  (0) 2019.12.15

 

I figured I would give myself some time off by watching some movies.

 

Contains Spoiler!

 

Protagonist in this story is Andy Dufrense played by Tim Robbins, a young person with many talents at that age and a position as a vice president in the bank. He was trialed for murder for his wife and her affair golf player. Andy was sentenced to prision and while inside, he meets Red, a man who can get things for him, and gets him an rock hammer. Andy gets on the good books with the Warden and Captain Hadley for doing taxes for them. 

 

I think the movies moral point is this: 

 

A man needs to have hope in any given situation, do not give up. Although unfairly sentenced to prison, Andy did not give up hope and with rock hammer carved a hole through the wall that would take 19 years for him to achieve. Along the way he did things that would remind him of his self value to keep sanity. Doing taxes for the guards, building a library, teaching a kid for a high school qualification exam all were not only done for good reasons but for himself as well. 

 

A movie I needed for myself in current situation. I graduated with a Chinese degree because I loved the feeling living abroad. After graduating, I realized I don't want to pursue a career where a language is a sole dependent cause like service industry. Realizing what I wanted to do, I studied coding. It has been about 8months now since I have taken this journey, and finding a job I want has not been easy. Have been through a lot of interviews and frankly companies I want to work for has not given a positive feedbacks. There will be and will always will be bumps and obstacles along the roads. But I know what I want to achieve and do, and like Andy, I should always have hope and constancy with discipline is key.

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
 
public class Main {
 
    public static int fibo(int floor, int people) {
        //층이 0층이면 그 층의 사람 리턴
        if(floor <= 0return people;
        //사람
        else if(people <= 0return 0;
        
        return fibo(floor - 1, people) + fibo(floor, people - 1);
        //ex floor 2 와 3people라고 가정을 하면
        //fibo(2, 3) = 
        //    fibo(1,3) + fibo(2,2)
        // 즉 fibo(1,3) 또한 = fibo(0,3) + fibo(1,2)
        //이런식으로 계속 내려가면 필요한 값이 나온다, 자세한건 블로그에 사진으로 계시
    
    }
    
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        int n = Integer.parseInt(br.readLine());
        while(n > 0) {
            //몇층
            int floor = Integer.parseInt(br.readLine());
            //사람수
            int people = Integer.parseInt(br.readLine());
            
            int result = fibo(floor, people);
            
            bw.write(String.valueOf(result) + "\n");
            n--;
            
        }
        bw.flush();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'알고리즘' 카테고리의 다른 글

백준 9단계(1978)  (0) 2019.12.21
백준 8단계(1011)  (0) 2019.12.21
백준 8단계(10250)  (0) 2019.12.15
백준 8단계(2869)  (0) 2019.12.15
백준 8단계(1193)  (0) 2019.12.14
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
52
53
54
 
public class Main {
 
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        
        //등차수열 문제랑 똑같은 방식으로 접근했습니다
        //문제 특성상 width는 필요성을 잘 모르겠네요
        int n = Integer.parseInt(br.readLine());
        int height, width, destination;
        
        //n은 몇번 숫자를 입력할지 정하는 변수
        while(n > 0) {
            //입력받고
            String str = br.readLine();
            StringTokenizer st = new StringTokenizer(str);
            //순서대로 변수에 값을 지정해주기
            height = Integer.parseInt(st.nextToken());
            width = Integer.parseInt(st.nextToken());
            destination = Integer.parseInt(st.nextToken());
            
            //몇번째 줄인지 확인해주는 변수
            int line = 1;
            //cnt는 height에서 시작해서 destination를 넘으면 stop
            int cnt = height;
            while(cnt < destination) {
                line++;
                cnt += height;
//                System.out.println("line is : " + line);
//                System.out.println("cnt is  : " + cnt);
            }
            //앞자리는 몇번째 층인지 구분을 해주고
            //뒷자리는 몇번째 출인지 확인을 해준다.
            //6 x 12의 10번째면 첫줄에 6명이 입실하고, 두번째줄에 4번째로 들어가는 방이 정답이니
            //402이다. 4번째층에 2번째줄, 만약 줄이 10보다 작으면 앞에 0를 추가하면 된다. 
            //앞자리 구하는 식
            String first = String.valueOf(destination - ((line - 1* height));
//            System.out.println("first part of the number is : " + first);
            //뒷자리 구하는 식
            String back = (line < 10)? "0" + (line): String.valueOf((line));
//            System.out.println("second part is : " + back);
            bw.write(first + back + "\n");
            n--;
        }
        bw.flush();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'알고리즘' 카테고리의 다른 글

백준 8단계(1011)  (0) 2019.12.21
백준 8단계(2775)  (0) 2019.12.15
백준 8단계(2869)  (0) 2019.12.15
백준 8단계(1193)  (0) 2019.12.14
백준 8단계(2292)  (0) 2019.12.14
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
 
public class Main {
 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str);
        
        //올라가는 변수
        long climb = Long.parseLong(st.nextToken());
        //흘러 내려가는 변수
        long fall = Long.parseLong(st.nextToken());
        //목표
        long destination = Long.parseLong(st.nextToken());
        //날
        //만약 (destination - fall) % (climb - fall)이 0이 아니면 나머지가 있다는 뜻으로 하루가 더 걸릴것이고
        //만약 0이면 남은 거리가 없다는 뜻으로 바로 나눈 값 출력하면된다 
        long day = ((destination - fall) % (climb - fall) == 0)? 
                (destination - fall) / (climb - fall) : (destination - fall) / (climb - fall) + 1 ;
        
        bw.write(String.valueOf(day));
        bw.flush();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'알고리즘' 카테고리의 다른 글

백준 8단계(2775)  (0) 2019.12.15
백준 8단계(10250)  (0) 2019.12.15
백준 8단계(1193)  (0) 2019.12.14
백준 8단계(2292)  (0) 2019.12.14
백준 8단계(2839)  (0) 2019.12.14

+ Recent posts