알고리즘/solved.ac

    [class4] (백준 1918) 후위 표기식

    HTML 삽입 미리보기할 수 없는 소스 #include #include using namespace std; int GetValue(char c) { switch (c) { case '+': return 1; case '-': return 1; case '*': return 2; case '/': return 2; case '(': return 3; case ')': return 3; } return -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string str; string result=""; stack s; cin >> str; for (int i = 0; i < str.length(); i++) { in..

    [class4] (백준 1865) 웜홀

    HTML 삽입 미리보기할 수 없는 소스 #include #include #include using namespace std; const int INF = 2000000000; string IsAble() { int n, m, w; vector load[501]; cin >> n >> m >> w; int s, e, t; for (int i = 0; i > s >> e >> t; bool check = false; load[s].push_back({ e,t }); load[e].push_back({ s,t }); } for (int i = 0; i > s >> e >> t; load[s].push_back({ e,t * (-1) }); } int..

    [class4] (백준 1167) 트리의 지름

    HTML 삽입 미리보기할 수 없는 소스 #include #include #include using namespace std; const int maxNum = 100001; int v; int maxLength = 0; int farNode = 1; vector tree[maxNum]; bool visit[maxNum] = {false}; void DFS(int startNode, int count) { visit[startNode] = true; for (auto i = tree[startNode].begin(); i first]) { DFS(i->first, count + i->second); } else { if (m..

    [class4] (백준 11404) 플로이드

    HTML 삽입 미리보기할 수 없는 소스 #include using namespace std; int n, m; const int maxNum = 20000000; int arr[101][101]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; int a, b, value; for (int start = 1; start a >> b >> value; if (arr[a][b] > value) { arr[a][b] = value; } } for (int waypoint = 1; waypoint

    [class4] (백준 2206) 벽 부수고 이동하기

    HTML 삽입 미리보기할 수 없는 소스 #include #include #include using namespace std; int N, M; int dx[4] = { 0,0,-1,1 }; int dy[4] = { -1, 1 ,0 ,0 }; char arr[1001][1001]; int visit[1001][1001][2] = {false}; int minNum = 1001; int BFS() { queue q; int count[1001][1001]; q.push({ {0,0},1 }); visit[0][0][1] = 1; while (!q.empty()) { int y = q.front().first.first; int x = q.front().first.second; int block = q.fro..

    [class4] (백준 1967) 트리의 지름

    HTML 삽입 미리보기할 수 없는 소스 root로 부터 가장 먼 point까지 구하는것은 스스로 구현했는데 가장 큰 2개의 point를 이용하는 식으로 답을 유도하려는 방식에서 틀렸다는것을 느꼈다. 다른분의 소스코드를 참고해서 그냥 가장 가중치가 높은 point하나에서 또다시 dfs구하면 되는것을 힌트로 얻어 구현했다. 아직 혼자서 구현하는 능력이 너무 부족한것같다. #include #include #include using namespace std; int N; vector node[10002]; bool visit[10002] = {false}; int result = 0; int point = 0; void dfs(int num, int len) { if (visit[num]) return; vis..