본문 바로가기

BOJ/C++

(202)
할로윈묘지 #define _CRT_SECURE_NO_WARNINGS #include #include #define INF 987654321 using namespace std; int map[31][31], dist[31][31]; typedef struct Pos { int sx, sy, ex, ey, cost; } Pos; int dx[4] = { 0, 0, -1,1 }, dy[4] = { -1,1,0,0 }; vector v; int main() { while (1) { int w, h, g, e; scanf("%d%d", &w, &h); if (w == 0 && h == 0) break; v.clear(); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++..
단어의 개수 *공백만으로 이루어진 단어인 경우 -> 0 *앞 뒤로 공백이 하나씩 있는 경우 -> cnt+1 *맨앞에 공백이 있는 경우 ->cnt+1 *맨 뒤에 공백이 있는 경우 ->cnt *공백이 하나도 없는 경우 -> 1 #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; getline(cin, s); //cin.ignore(); int cnt = 0; bool flag = false; for (int i = 0; i < s.size(); i++) { //맨 앞이 공백인 경우에는 단어의 개수로 세지 않는다. if (i == 0 && s[i] == ' ') contin..
역사 *플로이드 와샬 알고리즘과 위상정렬 사용 *플로이드 와샬 알고리즘으로 일단 두 정점의 선후관계가 있는지 파악한다. *선후관계가 없으면 0 *선후관계가 있는데 그 순서가 명확하지 않을 때는 위상정렬을 사용해서 비교한다. (위상정렬의 값이 더 큰 순서가 후이다.) #include #include #include #define INF 987654321 using namespace std; int dp[401][401]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i a >> b; dp[a][b] = 1; indegree[b]++; } for (int a = 1; a > a >> b;..
통나무 옮기기 *시뮬레이션 *통나무는 중간에 있는 좌표와 현재 방향(세로/가로)의 상태만 저장한다. #include #include #include #define INF 987654321 using namespace std; typedef pair pp; typedef pair ppi; typedef pair pppp; int n, ans = INF; char map[51][51]; ppi treeB, treeE; bool visited[51][51][2]; int dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }; int cdx[8] = { -1,-1,-1,0,0,1,1,1 }, cdy[8] = { -1,0,1,-1,1,-1,..
로봇청소기 + 테스트케이스 2019/09/10 - [BOJ/C++] - [BOJ] 아맞다우산 [BOJ] 아맞다우산 5 5 ##### #S..E #...# #..X# ##### 7 *물건을 찾으러 가는 순서에 따라서 최단 거리가 결정이 된다. *물건에 번호를 매겨서 비트마스킹으로 하려고 했으나, 매번 값이 달라짐 *시작점, 물건, 도착점을 모두 하나.. jayrightthere.tistory.com 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 ..
공주님을 구해라! *칼을 가지고 지나가는 경우와 아닌 경우를 나눠서 판단 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 #include #include #include using namespace std; int n, m, t, ans; int map[101][101]; bool visited[101][101..
알고스팟 *우선순위큐를 사용해서 더 적게 벽을 뿌순 순서대로 정렬하여 큐에서 꺼낸다. 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 #include #include #include #define INF 987654321 using namespace std; int n, m, ans = INF; int map[101][101]; typedef pair pp; typ..
달이 차오른다, 가자 *현재 가지고 있는 열쇠의 상태를 비트형태로 보존이 핵심 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 97 98 99 100 101 102 103 104 105 106 107 108 109 #include #include #include #define INF..