diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e84457a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "devon-aide.resourcePath": "/Users/jihwan/.vscode/extensions/lgcns-devon-aide.devon-aide-0.0.1/resource" +} \ No newline at end of file diff --git a/jihwan/week1/LongJump.cpp b/jihwan/week1/LongJump.cpp new file mode 100644 index 0000000..302b3f7 --- /dev/null +++ b/jihwan/week1/LongJump.cpp @@ -0,0 +1,25 @@ +#include +#include + +using namespace std; + +long long DP[2001]; //i번째 칸에 올 수 있는 경우의 수 저장 + +void dp(int n) { + DP[1]=1; //초기값 + DP[2]=1; + for(int i=1; i +#include + +using namespace std; +int visited[200]; +void dfs(int n, const vector>& computers) //연결되어있는 것들을 찾고 방문처리 +{ + visited[n] = 1; + for(int i=0; i> computers) { + int answer = 0; + for(int i=0; i +#include +#include +#include +using namespace std; + +int solution(vector numbers, int target) { + int answer = 0; + queue> q; + q.push({0,0}); + while(!q.empty()) + { + int a = q.front().first; //숫자의 합 + int cnt = q.front().second; //숫자의 개수 + q.pop(); + if(target==a && cnt==numbers.size()) answer++; //합이 target과 일치하고 numbers에 주어진 숫자만큼 사용했다면 정답++; + if(cnt>numbers.size()-1) continue; //numbers의 사이즈만큼 이미 사용했다면 push 하지 않고 다시. + else{ + q.push({a+numbers[cnt],cnt+1}); + q.push({a-numbers[cnt],cnt+1}); + } + } + + return answer; +} \ No newline at end of file diff --git a/jihwan/week5/delivery.cpp b/jihwan/week5/delivery.cpp new file mode 100644 index 0000000..1937f01 --- /dev/null +++ b/jihwan/week5/delivery.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std; +vector board[51]; +int cost[51][51]; +int dis[51]; +int visit[51]; +int solution(int N, vector > road, int K) { + int answer = 0; + for(int i=1; i<=N; i++)for(int j=1; j<=N; j++) cost[i][j]=-1; + for(auto&a:road) + { + board[a[0]].push_back(a[1]); + board[a[1]].push_back(a[0]); + if(cost[a[0]][a[1]]==-1||cost[a[0]][a[1]]>a[2]) cost[a[0]][a[1]] = a[2]; + if(cost[a[1]][a[0]]==-1||cost[a[1]][a[0]]>a[2]) cost[a[1]][a[0]] = a[2]; + } + queue> q; + q.push({1,0}); + for(int i=1; i<=N; i++) dis[i] = -1; + dis[1]=0; + while(!q.empty()) + { + int n = q.front().first; + int d = q.front().second; + q.pop(); + for(auto&a:board[n]) + { + if(dis[a]==-1||dis[a]>dis[n]+cost[n][a]) + { + dis[a]=dis[n]+cost[n][a]; + q.push({a,d+cost[n][a]}); + } + } + } + for(int i=1; i<=N; i++) if(dis[i]<=K) answer++; + return answer; +} \ No newline at end of file diff --git a/jihwan/week5/hotel.cpp b/jihwan/week5/hotel.cpp new file mode 100644 index 0000000..e2c1f7a --- /dev/null +++ b/jihwan/week5/hotel.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +using namespace std; + +int solution(vector> book_time) { + int answer = 0; + vector> v; + unordered_map m; + unordered_map mm; + for(auto&a:book_time) + { + int s = ((a[0][0]-'0')*10+(a[0][1]-'0'))*60 + (a[0][3]-'0')*10 + (a[0][4]-'0'); + int e = ((a[1][0]-'0')*10+(a[1][1]-'0'))*60 + (a[1][3]-'0')*10 + (a[1][4]-'0'); + v.push_back({s,e}); + } + sort(v.begin(),v.end()); + for(int i=0; i= e+10) + { + m[j] = 1; + e = v[j].second; + } + } + } + } + return answer; +} \ No newline at end of file diff --git a/jihwan/week6/DoubleQueue.cpp b/jihwan/week6/DoubleQueue.cpp new file mode 100644 index 0000000..bb0c36b --- /dev/null +++ b/jihwan/week6/DoubleQueue.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace std; + +map m; + +vector solution(vector operations) { + vector answer(2); + for(auto&s: operations) { + char cmd = s[0]; + string tmpValue = ""; + for(int i=2; i0) { + answer[1] = m.begin()->first; + answer[0] = prev(m.end())->first; + } + + return answer; +} diff --git a/jihwan/week6/EnglishGame.cpp b/jihwan/week6/EnglishGame.cpp new file mode 100644 index 0000000..87902d5 --- /dev/null +++ b/jihwan/week6/EnglishGame.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +map m; +vector solution(int n, vector words) { + vector answer; + answer.push_back(0); + answer.push_back(0); + string prevStr=""; + for(int i=0; i +#include +#include +using namespace std; + +vector tree[18]; +vector infoGlobal; +int ans = 0; +int n; + +void dfs(int sheep, int wolf, vector& candidates, vector& visited) { + ans = max(ans, sheep); + + for (int i = 0; i < (int)candidates.size(); ++i) { + int node = candidates[i]; + //늑대,양 수 업데이트 + int nsheep = sheep; + int nwolf = wolf; + if (infoGlobal[node] == 0) nsheep++; + else nwolf++; + + if (nwolf >= nsheep) continue; + + vector nextCandidates = candidates; + nextCandidates.erase(nextCandidates.begin() + i); + for (int c : tree[node]) { + if (!visited[c]) nextCandidates.push_back(c); + } + + visited[node] = true; + dfs(nsheep, nwolf, nextCandidates, visited); + visited[node] = false; + } +} + +int solution(vector info, vector> edges) { + infoGlobal = info; + n = info.size(); + ans = 0; + for (int i = 0; i < 18; ++i) tree[i].clear(); + + for (auto &e : edges) { + int parent = e[0], child = e[1]; + tree[parent].push_back(child); + } + + //초기 + vector visited(n, false); + visited[0] = true; + vector candidates; + for (int c : tree[0]) candidates.push_back(c); + + //시작할 때 양 1, 늑대 0 + dfs(1, 0, candidates, visited); + + return ans; +}