반응형

SSL 보안서버 인증서를 구매하여 사용하지 않고, Open SSL 인증서를 사용한 경우 git push시 SSL에러가 발생한다.


이를 해결하기 위해 CA에서 인증하는 절차를 무시하는 방법이 있다.

window 사용자는 cmd

mac 사용자는 terminal에서


1
git config --global http.sslVerify false
cs


명령어를 사용하여 global값을 설정한다.



반응형
반응형

문제풀이

dfs로 완전탐색하여 풀이하였다.

문제의 핵심은 가장 높은곳에서 시작하는 것과 공사를 오직 1번만 진행할 수 있다는 것이다.

input을 받을때 가장 큰 높이를 저장한 뒤 값을 참조하여 탐색한다. 처음에는 좌표를 저장하여 그 좌표에서만 시작하려 했는데 큰 차이는 없을것 같아 높이를 참조하여 시작점을 찾았다.

1. 내리막길인 경우 dfs로 길이를 구해주면 되고

2. 오르막길이고 공사를 진행한 적이 없다면 최소한의 높이를 깎은 뒤 내리막 길이 되면 dfs로 길이를 구해주면 된다. 이때 최대값 k만큼의 높이를 깎는다면 다음 좌표로 이동할 수 없을 수도 있으니 주의하자.


이후 dfs를 통해 등산로 길이의 최대값을 출력해주는 문제이다.


소스코드


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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <cstring>
#include <algorithm>
#define MAX 8
#define endl "\n"
using namespace std;
int n, k, maxHeight, ans;
int map[MAX][MAX];
bool visit[MAX][MAX];
int dx[] = {1-100};
int dy[] = {00-11};
 
// 모의 SW 역량테스트 1949 등산로 조성 
// 가장 높은곳에서 시작
// 높은 지형 -> 낮은 지형 상/하/좌/우 이동 
// 최대 k만큼 지형을 깎는다. (오직 한 지점에만 가능) 
 
// y좌표, x좌표, 현재까지 길이, 공사 여부 
void dfs(int y, int x, int cnt, bool isCutting) {
    ans = max(ans, cnt);
    
    for (int i=0; i<4; i++) {
        int ny=y+dy[i];
        int nx=x+dx[i];
        
        // map범위를 초과하거나 이미 방문한 지점이면 continue 
        if (ny<0 || nx<0 || ny>=|| nx>=|| visit[ny][nx]) continue;
        
        // 내리막길 
        if (map[y][x] > map[ny][nx]) {
            visit[ny][nx]=1;
            dfs(ny, nx, cnt+1, isCutting);
            visit[ny][nx]=0;
        } 
        
        // 오르막길 && 공사진행 X 
        else if (map[y][x] <= map[ny][nx] && !isCutting) {
            
            // 최소한으로 높이를 깎는다. 
            for (int d=1; d<=k; d++) {
                isCutting=1;
                map[ny][nx] -= d;
                
                // 내리막길이 되면 
                if (map[y][x] > map[ny][nx]) {
                    visit[ny][nx]=1;
                    dfs(ny, nx, cnt+1, isCutting);
                    visit[ny][nx]=0;
                }
                map[ny][nx] += d;
                isCutting=0;
            }    
        }
    }
}
 
void solve() {
    for (int y=0; y<n; y++) {
        for (int x=0; x<n; x++) {
            if (map[y][x] == maxHeight)    {
                visit[y][x]=1;
                dfs(y, x, 10);
                visit[y][x]=0;
            }
        }
    }
}
 
void init() {
    int tc;
    cin>>tc;
    for (int t=1; t<=tc; t++) {
        cin>>n>>k;
        memset(map, 0sizeof(map));
        memset(visit, 0sizeof(visit));
        ans = 1;
        maxHeight = 0;
        
        for (int y=0; y<n; y++) {
            for (int x=0; x<n; x++) {
                cin>>map[y][x];
                maxHeight = max(maxHeight, map[y][x]);    
            }
        }
        
        solve();
        
        cout<<"#"<<t<<" "<<ans<<endl;    
    }
}
 
int main() {
    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    init();
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[SWEA 1953] 탈주범 검거  (0) 2019.08.23
[SWEA 5644] 무선충전  (0) 2019.08.19
[SWEA 1208] Flatten  (0) 2019.07.29
[SWEA 1219] 길찾기  (0) 2019.07.24
[SWEA 2805] 농작물 수확하기  (0) 2019.07.23
반응형

최대점과 최소점의 차이를 가장 작게 하기 위해서는 가장 큰값을 빼고 가장 낮은값을 더해주면 된다.

즉, 배열을 먼저 sorting한 다음 덤프하는 수만큼 연산을 하고 sorting을 반복해주면 된다.


소스코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdio>
#include <algorithm>
#define MAX 100
using namespace std;
void solve() {
    int dumpCnt;
    for (int tc=1; tc<=10; tc++) {
        int map[MAX]={0,};
        scanf("%d"&dumpCnt);
        for (int i=0; i<MAX; i++scanf("%d"&map[i]);
        sort(map, map+MAX);
        for (int i=0; i<dumpCnt; i++) {
            map[0]++;
            map[MAX]--;
            sort(map, map+MAX);
        }
        
        printf("#%d %d\n", tc, map[MAX]-map[0]);
    }
}
int main() {
    solve();
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[SWEA 5644] 무선충전  (0) 2019.08.19
[SWEA 1949] 등산로 조성  (0) 2019.08.19
[SWEA 1219] 길찾기  (0) 2019.07.24
[SWEA 2805] 농작물 수확하기  (0) 2019.07.23
[SWEA 5162] 두가지 빵의 딜레마  (0) 2019.07.23
반응형

문제 설명이 좀 어렵게 되있는데 

dfs로 정점의 마지막까지 탐색한 뒤 길이 존재하면 1, 존재하지 않으면 0을 출력해주면 된다.



소스코드

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
#include <cstdio>
#include <cstring>
#define MAX 100
using namespace std;
int n, m;
bool isExisitRoad;
bool visit[MAX];
bool map[MAX][MAX];
void dfs(int s) {
    visit[s]=1;
    if(s==99) {
        isExisitRoad=1;
        return;
    }
    for (int x=0; x<MAX; x++) {
        if (map[s][x] && !visit[x])
            dfs(x);
    }
}
void solve() {
    for (int t=0; t<10; t++) {
        memset(map, 0sizeof(map));
        memset(visit, 0sizeof(visit));
        isExisitRoad=0;
        scanf("%d %d"&n, &m);
        int y, x;
        for (int i=0; i<m; i++) {
            scanf("%d %d"&y, &x);
            map[y][x]=1;
        }
        
        dfs(0);
        if (isExisitRoad) printf("#%d\n", n);
        else printf("#%d\n", n);
    }
}
int main() {
    solve();
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[SWEA 1949] 등산로 조성  (0) 2019.08.19
[SWEA 1208] Flatten  (0) 2019.07.29
[SWEA 2805] 농작물 수확하기  (0) 2019.07.23
[SWEA 5162] 두가지 빵의 딜레마  (0) 2019.07.23
[BOJ 7576] 토마토  (0) 2019.07.05
반응형

별찍기 문제처럼 접근했다. 

항상 map의 가로, 세로 길이가 홀수인것에서 힌트를 얻을 수 있었다.

가운데를 기준으로 세로로 접으면 대칭되는데 이 값들만 for루프를 통해 더해주면 되는 문제이다.

처음에 많이 헷갈렸는데 그림을 그려가면 규칙을 금방 찾을 수 있었던 문제


소스코드


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
#include <cstdio>
#include <cstring>
#define MAX 49
using namespace std;
int n;
int map[MAX][MAX];
int calcProfit() {
    int ret=0;
    int nHalf = n/2;
    for (int y=0; y<nHalf; y++
        for (int x=nHalf-y; x<=nHalf+y; x++
            ret += map[y][x];
        
    for (int y=nHalf; y>=0; y--
        for (int x=nHalf-y; x<=nHalf+y; x++)
            ret += map[n-1-y][x];
            
    return ret;
}
void solve() {
    int t;
    scanf("%d"&t);
    for (int i=1; i<=t; i++) {
        scanf("%d"&n);
        memset(map, 0sizeof(map));
        for (int y=0; y<n; y++)    
            for (int x=0; x<n; x++
                scanf("%1d"&map[y][x]);
        
        printf("#%d %d\n", i, calcProfit());
    }
}
int main(int argc, char** argv) {
    solve();
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[SWEA 1208] Flatten  (0) 2019.07.29
[SWEA 1219] 길찾기  (0) 2019.07.24
[SWEA 5162] 두가지 빵의 딜레마  (0) 2019.07.23
[BOJ 7576] 토마토  (0) 2019.07.05
[BOJ 1206] DFS와 BFS  (0) 2019.07.05
반응형

현미빵(a), 단호박 빵(b)중 더 싼 가격의 빵으로 현재 가지고 있는 돈(c)을 나눠주면 된다.


소스코드

1
2
3
4
5
6
7
8
9
10
11
#include <cstdio>
using namespace std;
int main(int argc, char** argv) {
    int t, a, b, c;
    scanf("%d"&t);
    for (int i=1; i<=t; i++) {
        scanf("%d %d %d"&a, &b, &c);
        printf("#%d %d\n", i, a>b?c/b:c/a);
    }
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[SWEA 1219] 길찾기  (0) 2019.07.24
[SWEA 2805] 농작물 수확하기  (0) 2019.07.23
[BOJ 7576] 토마토  (0) 2019.07.05
[BOJ 1206] DFS와 BFS  (0) 2019.07.05
[BOJ 1120]문자열  (0) 2019.07.03
반응형

문제출처

https://www.acmicpc.net/problem/7576


소스코드

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
#include <stdio.h>
#include <queue>
#define MAX 1000
using namespace std;
struct tomatoInfo {
    int cy, cx, time;
};
int n, m;
const int dx[] = {00-11};
const int dy[] = {1-100};
int map[MAX][MAX];
bool visit[MAX][MAX];
queue<tomatoInfo> q;
 
void init() {
    scanf("%d %d"&n, &m);
    for (int y=0; y<m; y++) {
        for (int x=0; x<n; x++) {
            scanf("%d"&map[y][x]);
            if (map[y][x] == 1) {
                q.push({y, x, 0});
                visit[y][x]=1;
            }
        }
    }
}
 
bool isOutOfBoundMap(int y, int x) {
    if (x<0 || y<0 || x>=|| y>=m) {
        return true;
    }
    return false;
}
 
bool checkMap() {
    for (int y=0; y<m; y++) {
        for (int x=0; x<n; x++) {
            if (map[y][x]==0) {
                return false;
            }
        }
    }
    return true;
}
 
void bfs() {
    int t;
    while (!q.empty()) {
        int y = q.front().cy;
        int x = q.front().cx;    
        t = q.front().time;
        q.pop();
        
        for (int i=0; i<4; i++) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            
            if (isOutOfBoundMap(ny, nx) || visit[ny][nx]) {
                continue;
            }
            if (map[ny][nx] == 0 && !visit[ny][nx]) {
                q.push({ny, nx, t+1});
                map[ny][nx]=1;
                visit[ny][nx]=1;
            }
        }
    }
    
    checkMap()==1 ? printf("%d", t) : printf("-1");    
}
int main() {
    init();
    bfs();
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[SWEA 2805] 농작물 수확하기  (0) 2019.07.23
[SWEA 5162] 두가지 빵의 딜레마  (0) 2019.07.23
[BOJ 1206] DFS와 BFS  (0) 2019.07.05
[BOJ 1120]문자열  (0) 2019.07.03
[BOJ 5585] 거스름돈  (0) 2019.07.03
반응형

문제출처

https://www.acmicpc.net/problem/1260


소스코드

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
#include <iostream>
#include <queue>
#include <cstring>
#define MAX 1000
using namespace std;
int n, m, v;
int map[MAX][MAX];
bool visit[MAX];
 
void init() {
    cin>>n>>m>>v;
    int s,e;
    for (int i=0; i<m; i++) {
        cin>>s>>e;
        map[s][e]=1;
        map[e][s]=1;
    }
}
 
void dfs(int s) {
    visit[s]=1;
    cout<<s<<" ";
    for (int i=0; i<=n; i++) {
        if (!visit[i] && map[s][i] == 1) {
            dfs(i);
        }
    }
}
 
void bfs(int s) {
    queue<int> q;
    q.push(s);
    visit[s]=1;
    
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        cout<<cur<<" ";
        for (int i=0; i<=n; i++) {
            if (!visit[i] && map[cur][i] == 1) {
                q.push(i);
                visit[i]=1;
            }
        }
    }
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    init();
    dfs(v);
    memset(visit, 0sizeof(visit));
    cout<<"\n";
    bfs(v);
    return 0;
}
 
cs


반응형

'Algorithm' 카테고리의 다른 글

[SWEA 5162] 두가지 빵의 딜레마  (0) 2019.07.23
[BOJ 7576] 토마토  (0) 2019.07.05
[BOJ 1120]문자열  (0) 2019.07.03
[BOJ 5585] 거스름돈  (0) 2019.07.03
[BOJ 4948] 베르트랑 공준  (0) 2019.07.03
반응형

문제출처

https://www.acmicpc.net/problem/1120


처음에는 x문자열과 y문자열을 최대한 맞춰가면서 풀이해야 한다고 생각해서 많이 어려움을 느꼈다.

하지만 결국 앞이던 뒤던 y문자열과 비슷한 최적의 경우를 찾는 것이기 때문에 구현 대상에서 제외하고

x문자열과 y문자열의 차이값을 찾아가면서 구현했다.


예를 들어 설명하면 다음과 같다.

x가 adaabc

y가 aababbc 인경우를 생각해보면 문자열의 길이 차이는 1만큼 난다.


이때, y[0]부터 y[5]까지와 x를 비교해서 차이값, y[1]부터 y[6]까지와 x를 비교해서 차이값의 최솟값을 출력해주면 되는 문제이다.


소스코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#define MAX 987654321
using namespace std;
int min(int a, int b) {
    return a>=b ? b : a;
}
int main(int argc, char** argv) {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string x,y;
    int ans=MAX;
    cin>>x>>y;
    for (int i=0; i<= y.size() - x.size(); i++) {
        int cnt = 0;
        int yIdx=i;
        for (int j=0; j < x.size(); j++, yIdx++) {
            if (x[j] == y[yIdx]) continue;
            cnt++;
        }
        ans = min(ans, cnt);
    }
    cout<<ans;
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[BOJ 7576] 토마토  (0) 2019.07.05
[BOJ 1206] DFS와 BFS  (0) 2019.07.05
[BOJ 5585] 거스름돈  (0) 2019.07.03
[BOJ 4948] 베르트랑 공준  (0) 2019.07.03
[BOJ 10872] 팩토리얼  (0) 2019.07.03
반응형

문제 출처

https://www.acmicpc.net/problem/5585


소스코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
// 단순 반복문 문제
// greedy algorithm
int main(int argc, char** argv) {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int coins[] = {500100501051};
    int nCost, ans=0;
    cin>>nCost;
    int nRemainder = 1000 - nCost;
    for (int i=0; i<6; i++) {
        while (nRemainder - coins[i] >= 0) {
            nRemainder -= coins[i];
            ans++;
            if (nRemainder == 0) {
                break;
            }
        }
    }
    cout<<ans;
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[BOJ 1206] DFS와 BFS  (0) 2019.07.05
[BOJ 1120]문자열  (0) 2019.07.03
[BOJ 4948] 베르트랑 공준  (0) 2019.07.03
[BOJ 10872] 팩토리얼  (0) 2019.07.03
[프로그래머스 12936] 줄 서는 방법  (0) 2019.04.23

+ Recent posts