Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"devon-aide.resourcePath": "/Users/jihwan/.vscode/extensions/lgcns-devon-aide.devon-aide-0.0.1/resource"
}
25 changes: 25 additions & 0 deletions jihwan/week1/LongJump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <string>
#include <vector>

using namespace std;

long long DP[2001]; //i번째 칸에 올 수 있는 경우의 수 저장

void dp(int n) {
DP[1]=1; //초기값
DP[2]=1;
for(int i=1; i<n; i++) {
if(i+1<=n) { // 1칸 이동하는 경우 현재칸까지 오는 경우의수를 i+1칸에 더해줌
DP[i+1] = (DP[i+1]+DP[i])%1234567;
}
if(i+2<=n) { //위와 동일
DP[i+2] = (DP[i+2]+DP[i])%1234567;
}
}
}
long long solution(int n) {
long long answer = 0;
dp(n);
answer = DP[n];
return answer;
}
28 changes: 28 additions & 0 deletions jihwan/week1/Network.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <string>
#include <vector>

using namespace std;
int visited[200];
void dfs(int n, const vector<vector<int>>& computers) //연결되어있는 것들을 찾고 방문처리
{
visited[n] = 1;
for(int i=0; i<computers.size(); i++)
{
if(computers[n][i]==1)
{
if(visited[i]!=1) dfs(i,computers);
}
}
}
int solution(int n, vector<vector<int>> computers) {
int answer = 0;
for(int i=0; i<n; i++)
{
if(visited[i]!=1) // 방문처리 되지 않은 컴퓨터를 기준으로 연결되어있는 것들 찾기
{
dfs(i,computers);
answer++;
}
}
return answer;
}
25 changes: 25 additions & 0 deletions jihwan/week1/TargetNumber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <string>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;

int solution(vector<int> numbers, int target) {
int answer = 0;
queue<pair<int,int>> 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;
}
39 changes: 39 additions & 0 deletions jihwan/week5/delivery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> board[51];
int cost[51][51];
int dis[51];
int visit[51];
int solution(int N, vector<vector<int> > 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<pair<int,int>> 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;
}
39 changes: 39 additions & 0 deletions jihwan/week5/hotel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;

int solution(vector<vector<string>> book_time) {
int answer = 0;
vector<pair<int,int>> v;
unordered_map<int,int> m;
unordered_map<int,int> 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<v.size(); i++)
{
if(m[i]==0)
{
answer++;
int s = v[i].first;
int e = v[i].second;
m[i]=1;
for(int j=i+1; j<v.size(); j++)
{
if(m[j]==0 && v[j].first >= e+10)
{
m[j] = 1;
e = v[j].second;
}
}
}
}
return answer;
}
34 changes: 34 additions & 0 deletions jihwan/week6/DoubleQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <string>
#include <vector>
#include <map>

using namespace std;

map<int,int> m;

vector<int> solution(vector<string> operations) {
vector<int> answer(2);
for(auto&s: operations) {
char cmd = s[0];
string tmpValue = "";
for(int i=2; i<s.length(); i++) {
tmpValue += s[i];
}
int value = stoi(tmpValue);

if(cmd=='I') {
m[value]=1;
}
else if(cmd=='D' && !m.empty()) {
if(value == 1) m.erase(prev(m.end()));
else m.erase(m.begin());
}
}

if(m.size()>0) {
answer[1] = m.begin()->first;
answer[0] = prev(m.end())->first;
}

return answer;
}
32 changes: 32 additions & 0 deletions jihwan/week6/EnglishGame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <string>
#include <vector>
#include <map>

using namespace std;

map<string,int> m;
vector<int> solution(int n, vector<string> words) {
vector<int> answer;
answer.push_back(0);
answer.push_back(0);
string prevStr="";
for(int i=0; i<words.size(); i++) {
string word = words[i];
if ( i==0 || (m[word]!=1 && prevStr[prevStr.size()-1]==word[0])) {
m[word]=1;
prevStr = word;
}
else {
int idx = (i+1)%n;
if(idx==0) idx = n;
int turn = i/n+1;

answer[0] = idx;
answer[1] = turn;

break;
}
}

return answer;
}
57 changes: 57 additions & 0 deletions jihwan/week6/SheepAndWolf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> tree[18];
vector<int> infoGlobal;
int ans = 0;
int n;

void dfs(int sheep, int wolf, vector<int>& candidates, vector<bool>& 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<int> 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<int> info, vector<vector<int>> 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<bool> visited(n, false);
visited[0] = true;
vector<int> candidates;
for (int c : tree[0]) candidates.push_back(c);

//시작할 때 양 1, 늑대 0
dfs(1, 0, candidates, visited);

return ans;
}