알고리즘

    [class4] (백준 11444) 피보나치 수 6

    HTML 삽입 미리보기할 수 없는 소스 #include using namespace std; struct Matrix { long long num[2][2]; }; long long n; const long long HashNum = 1000000007; long long GetHasingMultiplyResult(long long a, long long b, long long c, long long d) { long long result = ((a % HashNum * b) % HashNum) + ((c % HashNum * d) % HashNum); return result % HashNum; } Matrix multiply(Matrix a, Matrix b) { Matrix result; resul..

    [class4] (백준 2263) 트리의 순회

    HTML 삽입 미리보기할 수 없는 소스 #include using namespace std; const int maxnum = 100001; int postorder[maxnum]; int inorder[maxnum]; int index[maxnum]; void PrintPreorder(int istart, int iend, int pstart, int pend) { if (istart > iend || pstart > pend) return; int rootnum = index[postorder[pend]]; int left = rootnum - istart; int right = iend - rootnum; cout n; for (int i = 1; i > inorder[i]; index[inorde..

    [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