[C++] 백준 2250 트리의 높이와 너비
·
Algorithm/Baekjoon
#include #include #include #include using namespace std; const int MaxNode = 10001; int x = 1, maxY = 0; pair nodes[MaxNode];//노드들을 받아온다. vector pos[MaxNode];//노드들의 위치를 저장한다. bool visited[MaxNode];//노드를 갔나의 표시 void MidCycle(int y, int curr); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, level = 1, length = 1; cin >> n; for (int i = 0; i < n; i++) { int temp1, temp2, temp3; cin..
[C++] 백준 1991 트리 순회
·
Algorithm/Baekjoon
#include #include #include using namespace std; int n; map nodes;//노드들을 받아온다. map visited;//노드를 갔나의 표시 void FirstCycle(char curr); void MidCycle(char curr); void EndCycle(char curr); void memsetting(int n); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > temp1 >> temp2 >> temp3; nodes[temp1].first = temp2; nodes[temp..
[C++] 백준 1939 중량제한
·
Algorithm/Baekjoon
#include #include #include #include using namespace std; const int MaxNum = 100001; int n, m, start, finish; bool visited[MaxNum]; vector nodes[MaxNum]; bool BFS(int cost); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int lowCost, highCost, maxCost; cin >> n >> m; for (int i = 0; i > temp1 >> temp2 >> temp3; nodes[temp1].push_back({ temp2, temp..
[C++] 백준 2110 공유기 설치
·
Algorithm/Baekjoon
#include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); vector house; int n, m, maxDist, minDist, midDist, curr, result = 0; cin >> n >> m; for (int i = 0; i > temp; house.push_back(temp); } sort(house.begin(), house.end()); minDist = 1;//제일 짧은 거리 maxDist = house[n - 1];//가장 긴 거리 while (minDist = midDist)//공유기 깐 지점에서 다음 ..
[C++] 백준 1236 성 지키기
·
Algorithm/Baekjoon
#include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; char data[50][50]; int x[50], y[50]; cin >> n >> m; for (int i = 0; i > data[i][j]; if (data[i][j] == 'X') { x[j] = 1;//그 열이나 행에 있어도 1로 표시하여 없는 행을 구한다. y[i] = 1; } } } int xCount = 0; for (int j = 0; j < m; j++) { if (x[j] == 0) xCount++;//없는 행의..
[C++] 백준 1668 트로피 진열
·
Algorithm/Baekjoon
#include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); vector num; int n, m[2], max = 0; cin >> n; for (int i = 0; i > m[0]; num.push_back(m[0]); } m[0] = 0; m[1] = 0; for (int i = 0; i = 0; i--) { if (max < num[i]) { max = num[i]; m[1]++; } } cout