Skip to content

Commit

Permalink
Merge branch 'main' into 17-yuyu0830
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu0830 authored Jul 14, 2024
2 parents c1fae0b + d1aa6c6 commit 81cf867
Show file tree
Hide file tree
Showing 11 changed files with 488 additions and 2 deletions.
143 changes: 143 additions & 0 deletions InSange/BFS/18352.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//#include <iostream>
//#include <queue>
//#include <vector>
//
//using namespace std;
//
//int N, M, K, X, a, b, minDist;
//deque<deque<int>> town;
//queue<int> q;
//vector<int> dist;
//vector<int> answer;
//
//void Solve()
//{
// cin >> N >> M >> K >> X;
// N++;
// town.assign(N, deque<int>());
// dist.assign(N, -1);
//
// for (int i = 0; i < M; i++)
// {
// cin >> a >> b;
//
// town[a].push_back(b);
// }
//
// minDist = -1;
// q.push(X);
// dist[X] = 0;
//
// while (!q.empty())
// {
// int cur = q.front();
// q.pop();
//
// for (const int& val : town[cur])
// {
// if (dist[val] != -1) continue;
// q.push(val);
// dist[val] = dist[cur] + 1;
// minDist = max(minDist, dist[val]);
// }
// }
//
// for (int i = 0; i < dist.size(); i++)
// {
// if (dist[i] == K) answer.push_back(i);
// }
//
// if (answer.size())
// {
// for (const int& val : answer)
// {
// cout << val << "\n";
// }
// }
// else cout << -1;
//}
//
//int main()
//{
// cin.tie(nullptr);
// ios::sync_with_stdio(false);
//
// Solve();
//
// return 0;
//}

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int N, M, K, X, A, B;
int cur, dist;
queue<pair<int, int>> q;
vector<vector<int>> towns;
vector<bool> visited;
priority_queue<int, vector<int>, greater<int>> answer;

void Solve()
{
cin >> N >> M >> K >> X;

N++;
towns.assign(N, vector<int>());
visited.assign(N, false);

while (M--)
{
cin >> A >> B;
towns[A].push_back(B);
}

q.push({ X, 0 });
visited[X] = true;

while (!q.empty())
{
cur = q.front().first;
dist = q.front().second;

q.pop();

if (dist == K)
{
answer.push(cur);
continue;
}

for (auto v : towns[cur])
{
if (visited[v]) continue;
q.push({ v, dist + 1 });
visited[v] = true;
}
}

if (answer.empty())
{
cout << -1;
return;
}

while (!answer.empty())
{
cout << answer.top() << "\n";
answer.pop();
}
return;
}

int main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);

Solve();

return 0;
}
7 changes: 6 additions & 1 deletion InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
| 8์ฐจ์‹œ | 2024.04.09 | ํˆฌ ํฌ์ธํ„ฐ | [๋‘ ์šฉ์•ก](https://www.acmicpc.net/problem/2470) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/32)]
| 9์ฐจ์‹œ | 2024.04.12 | ํž™ | [Top K Frequent Words](https://leetcode.com/submissions/detail/1180988760/) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)]
| 10์ฐจ์‹œ | 2024.04.30 | ์Šคํƒ | [์˜ค์•„์‹œ์Šค ์žฌ๊ฒฐํ•ฉ](https://www.acmicpc.net/problem/3015) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/40)]
| 11์ฐจ์‹œ | 2024.05.03 | DFS | [์ˆซ์ž๊ณ ๋ฅด๊ธฐ](https://www.acmicpc.net/problem/2668) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/41)]
| 11์ฐจ์‹œ | 2024.05.03 | DFS | [์ˆซ์ž๊ณ ๋ฅด๊ธฐ](https://www.acmicpc.net/problem/2668) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/41]
| 12์ฐจ์‹œ | 2024.05.08 | DP | [์ „๊นƒ์ค„](https://www.acmicpc.net/problem/2565) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/46)]
| 13์ฐจ์‹œ | 2024.05.22 | BFS | [ํŠน์ • ๊ฑฐ๋ฆฌ์˜ ๋„์‹œ ์ฐพ๊ธฐ](https://www.acmicpc.net/problem/18352) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/53)]
| 14์ฐจ์‹œ | 2024.05.27 | ํˆฌ ํฌ์ธํ„ฐ | [ํฌ๋„์ฃผ ์‹œ์Œ](https://www.acmicpc.net/problem/31589) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/56)]
| 15์ฐจ์‹œ | 2024.05.27 | ์ •๋ ฌ | [ํ†ต๋‚˜๋ฌด ๊ฑด๋„ˆ๋›ฐ๊ธฐ](https://www.acmicpc.net/problem/11497) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/57)]
| 16์ฐจ์‹œ | 2024.06.28 | ๊ทธ๋ž˜ํ”„ | [Maximum_Total_Importance_ofRoads](https://leetcode.com/problems/maximum-total-importance-of-roads/) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/63)]
| 17์ฐจ์‹œ | 2024.06.28 | ๋ฌธ์ž์—ด | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion/) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/64)]
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <vector>
#include <queue>

using namespace std;

class Solution {
public:
long long maximumImportance(int n, vector<vector<int>>& roads) {
vector<vector<int>> conn; // road
priority_queue<pair<long long, int>> pq; // connect degree first: degree, second: index
long long answer = 0;

conn.assign(n, vector<int>());

for (auto road : roads)
{
int v1 = road[0];
int v2 = road[1];

conn[v1].push_back(v2);
conn[v2].push_back(v1);
}

for (int i = 0; i < n; i++)
{
pq.push({ conn[i].size(), i });
}

while (!pq.empty())
{
pair<long long, int> cur;
cur = pq.top();
pq.pop();

answer += (n-- * cur.first);
}

return answer;
}
};
35 changes: 35 additions & 0 deletions InSange/๋ฌธ์ž์—ด/6_Zigzag Conversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
string convert(string s, int numRows) {
if (numRows <= 1 || s.size() <= numRows) return s;

vector<string>v(numRows, "");

int i, j, dir;
j = 0;
dir = -1;

for (i = 0; i < s.size(); i++)
{
if (j == numRows - 1 || j == 0) dir *= -1;
v[j] += s[i];
if (dir == 1) j++;
else j--;
}

string answer;
answer = "";

for (auto c : v)
{
answer += c;
}

return answer;
}
};
61 changes: 61 additions & 0 deletions InSange/์ •๋ ฌ/11497.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int T, N, num, answer;
priority_queue < int> pq;
deque<int> logs;

void Solve()
{
cin >> T;

while (T--)
{
answer = 0;
cin >> N;

for (int i = 0; i < N; i++)
{
cin >> num;
pq.push(num);
}

bool isLeft = true;

while (!pq.empty())
{
if (isLeft)
logs.push_front(pq.top());
else //if(!isLeft)
logs.push_back(pq.top());

pq.pop();
isLeft = (isLeft ? false : true);
}

int lsize = logs.size();

for (int i = 0; i < lsize; i++)
{
int next = (i + 1) % lsize;
answer = max(answer, abs(logs[i] - logs[next]));
}

cout << answer << "\n";;
logs.clear();
}

}

int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

Solve();

return 0;
}
57 changes: 57 additions & 0 deletions InSange/ํˆฌํฌ์ธํ„ฐ/31589.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, K, l, r, lastDrink;
vector<int> wine;
bool isLeft = false;
long long answer = 0;

void Solve()
{
cin >> N >> K;

wine.assign(N, 0);

for (int i = 0; i < N; i++)
{
cin >> wine[i];
}

sort(wine.begin(), wine.end());

l = 0;
r = N - 1;
answer = 0;
lastDrink = 0;

while (K--)
{
if (isLeft == true) // ยธร€ ยพรธยดร‚ ยฐร…
{
lastDrink = wine[l];
l++;
}
else// if(isLeft == false) // ยธร€ ร€ร–ยดร‚ ยฐร…
{
answer += wine[r] - lastDrink;
r--;
}

isLeft = (isLeft + 1) & 1;
}

cout << answer;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

Solve();

return 0;
}
6 changes: 6 additions & 0 deletions seongwon030/DP/์—ฐ์†ํ•ฉ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
n = int(input())
m = list(map(int,input().split()))

for i in range(1,n):
m[i] = max(m[i], m[i]+m[i-1])
print(max(m))
5 changes: 4 additions & 1 deletion seongwon030/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
| 10์ฐจ์‹œ | 2024.05.07 | ์ˆ˜ํ•™ | [์—ฐ์† ํ•ฉ](https://www.acmicpc.net/problem/2737) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/43) |
| 11์ฐจ์‹œ | 2024.05.07 | DP | [ํ•ฉ๋ถ„ํ•ด](https://www.acmicpc.net/problem/2225) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/44) |
| 12์ฐจ์‹œ | 2024.05.13 | ๋ธŒ๋ฃจํŠธํฌ์Šค | [์•”ํ˜ธ๋งŒ๋“ค๊ธฐ](https://www.acmicpc.net/problem/1759) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/50) |
| 13์ฐจ์‹œ | 2024.05.23 | ๋ถ„ํ• ์ •๋ณต | [ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 6](https://www.acmicpc.net/problem/11444) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/54) |
| 13์ฐจ์‹œ | 2024.05.23 | ๋ถ„ํ• ์ •๋ณต | [ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 6](https://www.acmicpc.net/problem/11444) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/55) |
| 14์ฐจ์‹œ | 2024.05.28 | ํ | [๊ฐ€์šด๋ฐ๋ฅผ ๋งํ•ด์š”](https://www.acmicpc.net/problem/1655) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/58) |
| 15์ฐจ์‹œ | 2024.06.01 | ํ | [์ค‘์•™๊ฐ’ ๊ตฌํ•˜๊ธฐ](https://www.acmicpc.net/problem/2696) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/61) |
| 16์ฐจ์‹œ | 2024.07.04 | DP | [์—ฐ์†ํ•ฉ](https://www.acmicpc.net/problem/1912) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/66) |

---
2 changes: 2 additions & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
| 12์ฐจ์‹œ| 2024.05.13 | ํ•ด์‹œ | [๋‘ ๋ฐฐ์—ด์˜ ํ•ฉ](https://www.acmicpc.net/problem/2143) | - |
| 13์ฐจ์‹œ| 2024.05.21 | LIS | [๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด 2](https://www.acmicpc.net/problem/12015) | - |
| 14์ฐจ์‹œ| 2024.07.02 | ์œ„์ƒ์ •๋ ฌ | [ACM Craft](https://www.acmicpc.net/problem/1005) | - |
| 15์ฐจ์‹œ| 2024.06.01 | ๊ธฐํ•˜ | [๋‹ค๊ฐํ˜•์˜ ๋ฉด์ ](https://www.acmicpc.net/problem/2166) | - |
| 16์ฐจ์‹œ| 2024.06.04 | ๋ณ„์ž๋ฆฌ ๋งŒ๋“ค๊ธฐ | [๋ณ„์ž๋ฆฌ ๋งŒ๋“ค๊ธฐ](https://www.acmicpc.net/problem/4386) | - |
---
Loading

0 comments on commit 81cf867

Please sign in to comment.