Skip to content

Commit

Permalink
Merge branch 'main' into 10-yuyu0830
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu0830 authored May 21, 2024
2 parents f990038 + 81387c2 commit 67ffa0d
Show file tree
Hide file tree
Showing 21 changed files with 740 additions and 90 deletions.
60 changes: 60 additions & 0 deletions InSange/DFS/2668.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, num;
vector<bool> visited;
vector<int> v;
vector<int> answer;

void DFS(int cur, int start)
{
if (visited[cur] == true)
{
if (start == cur) answer.push_back(start);
return;
}

visited[cur] = true;
DFS(v[cur], start);
visited[cur] = false;
}

void Solve()
{
cin >> N;

N += 1;
visited.assign(N, false);
v.assign(N, 0);

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

for (int i = 1; i < N; i++)
{
DFS(i, i);
}

int asize = answer.size();
cout << asize << "\n";

for (int i = 0; i < asize; i++)
{
cout << answer[i] << "\n";
}
}

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

Solve();

return 0;
}
8 changes: 6 additions & 2 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
| 3์ฐจ์‹œ | 2024.03.19 | ํ”Œ๋กœ์ด๋“œ ์›Œ์…œ | [์•ฑ](https://www.acmicpc.net/problem/7579) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/9) |
| 4์ฐจ์‹œ | 2024.03.25 | ๋‹ค์ต์ŠคํŠธ๋ผ | [ํŒŒํ‹ฐ](https://www.acmicpc.net/problem/1238) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/15)|
| 5์ฐจ์‹œ | 2024.03.27 | DP | [RGB๊ฑฐ๋ฆฌ2](https://www.acmicpc.net/problem/17404) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)]
| 6์ฐจ์‹œ | 2024.04.01 | ์ตœ์†Œ์‹ ์žฅํŠธ๋ฆฌ | [ํ–‰์„ฑ ํ„ฐ๋„](https://www.acmicpc.net/problem/2887) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/19)]
=======
| 6์ฐจ์‹œ | 2024.04.01 | ์ตœ์†Œ์‹ ์žฅํŠธ๋ฆฌ | [ํ–‰์„ฑ ํ„ฐ๋„](https://www.acmicpc.net/problem/2887) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/24)]
| 7์ฐจ์‹œ | 2024.04.04 | ์Šคํƒ | [๋ฌธ์ž์—ด ํญ๋ฐœ](https://www.acmicpc.net/problem/9935) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/28)]
| 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.05.02 | ์Šคํƒ | [์˜ค์•„์‹œ์Šค ์žฌ๊ฒฐํ•ฉ](https://www.acmicpc.net/problem/3015) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/40)]
| 11์ฐจ์‹œ | 2024.05.02 | DFS | [์ˆซ์ž๊ณ ๋ฅด๊ธฐ](https://www.acmicpc.net/problem/2668) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/41)]
---
62 changes: 62 additions & 0 deletions InSange/์Šคํƒ/3015.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

long long N, n, a, b, answer;
vector<int> line;
stack<pair<int, int>> st;

// a1 ๋ณด๋‹ค b๊ฐ€ ํฌ๋ฉด ์ข…๋ฃŒ
// a1 ๋ณด๋‹ค b๊ฐ€ ์ž‘๋‹ค๋ฉด ๋‹ค์Œ b๋Š”
void Solve()
{
cin >> N;

for (int i = 0; i < N; i++)
{
cin >> n;
line.push_back(n);
}

for (auto num : line)
{
int cnt = 1;

while (!st.empty())
{
int cur = st.top().first;
int cur_cnt = st.top().second;
if (cur < num)
{
answer+= cur_cnt;
}
else if (cur == num)
{
answer += cur_cnt;
cnt += cur_cnt;
}
else //if(st.top().first > num)
{
answer++;
break;
}
st.pop();
}
//cout << num << ", " << answer << "\n";
st.push({num, cnt});
}

cout << answer;
}

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

Solve();

return 0;
}
54 changes: 54 additions & 0 deletions InSange/์Šคํƒ/9935.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <iostream>

using namespace std;

string s, boom;
int blen;

void Solve()
{
cin >> s >> boom;

blen = boom.length();

string st = "";
for (char c : s)
{
st.push_back(c);

if (c == boom[blen-1] && st.size() >= blen)
{
bool flag = true;

for (int i = 0; i < blen; i++)
{
if (boom[i] != st[st.length() - blen + i])
{
flag = false;
break;
}
}

if (flag)
{
for (int i = 0; i < blen; i++)
{
st.pop_back();
}
}
}
}

if (st == "") cout << "FRULA";
else cout << st;
}

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

Solve();

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

using namespace std;

const int MAX_VAL = 1999999999;

int N, num, minVal, aanswer, banswer;
vector<int> acid; // ยปรชยผยบ
vector<int> basic; // ยฟยฐยฑรขยผยบ

bool cmp(int a, int b)
{
return a > b;
}

void Input()
{
cin >> N;

for (int i = 0; i < N; i++)
{
cin >> num;
(num > 0) ? acid.push_back(num) : basic.push_back(num);
}

sort(acid.begin(), acid.end());
sort(basic.begin(), basic.end(), cmp);

minVal = MAX_VAL;
}

void Solve()
{
int a_index = 0;
int b_index = 0;
while (a_index < acid.size() && b_index < basic.size())
{
int anum, bnum;
anum = acid[a_index];
bnum = basic[b_index];

if (abs(anum + bnum) < minVal)
{
aanswer = anum;
banswer = bnum;
minVal = abs(anum + bnum);
}

(abs(anum) > abs(bnum)) ? b_index++ : a_index++;
}

int sum;
if (acid.size() > 1)
{
sum = abs(acid[0] + acid[1]);
if (sum < minVal)
{
aanswer = acid[1];
banswer = acid[0];
}
}
if (basic.size() > 1)
{
sum = abs(basic[0] + basic[1]);
if (sum < minVal)
{
aanswer = basic[0];
banswer = basic[1];
}
}
if (acid.empty())
{
aanswer = basic[0];
banswer = basic[1];
}
if (basic.empty())
{
aanswer = acid[1];
banswer = acid[0];
}

cout << banswer << " " << aanswer;
}

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

Input();
Solve();

return 0;
}
34 changes: 34 additions & 0 deletions InSange/ํž™/Top K Frequent Words.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>

using namespace std;

class Solution {
public:
struct compare {
bool operator()(pair<int, string>& a, pair<int, string>& b)
{
if (a.first == b.first) return a.second > b.second;
return a.first < b.first;
}
};

vector<string> topKFrequent(vector<string>& words, int k) {
unordered_map<string, int> um;
priority_queue<pair<int, string>, vector<pair<int, string>>, compare> pq;
vector<string> ans;

for (auto s : words) um[s]++;
for (pair<string, int> v : um) pq.push({ v.second, v.first });

while (k--)
{
ans.push_back(pq.top().second);
pq.pop();
}

return ans;
}
};
4 changes: 2 additions & 2 deletions dhlee777/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
| 2์ฐจ์‹œ | 2024.03.18 | DP | [์‰ฌ์šด๊ณ„๋‹จ์ˆ˜](https://www.acmicpc.net/problem/10844) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/8)|
| 3์ฐจ์‹œ | 2024.03.23 | union-find | [์ง‘ํ•ฉ์˜ ํ‘œํ˜„](https://www.acmicpc.net/problem/1717) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/14)|
| 4์ฐจ์‹œ | 2024.03.25 | BFS | [๋ฐ”์ด๋Ÿฌ์Šค](https://www.acmicpc.net/problem/2606) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/17)|
| 5์ฐจ์‹œ | 2024.03.30 | MST | [์ตœ์†Œ์ŠคํŒจ๋‹ํŠธ๋ฆฌ](https://www.acmicpc.net/problem/1197) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/21)|
| 5์ฐจ์‹œ | 2024.03.30 | mst | [์ตœ์†Œ์ŠคํŒจ๋‹ํŠธ๋ฆฌ](https://www.acmicpc.net/problem/1197) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/21)|
| 6์ฐจ์‹œ | 2024.04.04 | backtracking | [์Šคํƒ€ํŠธ์™€๋งํฌ](https://www.acmicpc.net/problem/14889) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/29)|
---
| 7์ฐจ์‹œ | 2024.04.08 | backtracking | [n๊ณผm(5)](https://www.acmicpc.net/problem/15654) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/31)|
36 changes: 36 additions & 0 deletions dhlee777/backtracking/n๊ณผm(5).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int num_size, picked_size;
int num[8]; //์ž…๋ ฅ๋ฐ›์€ ์ˆซ์ž๋“ค์„ ์ €์žฅํ•˜๋Š” ๋ฐฐ์—ด
bool visited[8]; //๋ฐฉ๋ฌธํ–ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ์œ„ํ•œ ๋ฐฐ์—ด
vector<int>v; //์ˆซ์ž๋“ค์„ ์ˆœ์„œ๋Œ€๋กœ ๋„ฃ๊ธฐ์œ„ํ•œ ๋ฒกํ„ฐ
void dfs(int cnt, int vt) { //cnt๋Š” ๋ฐฉ๋ฌธ์ˆซ์ž ์นด์šดํŒ…,vt๋Š” ํ˜„์žฌ ์ˆซ์ž๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.
if (cnt == picked_size) { // ๋ฐฉ๋ฌธํ•œ ์ˆ˜์™€ ์ž…๋ ฅ๋ฐ›์€ ๊ณจ๋ผ์•ผํ•˜๋Š” ๊ฐœ์ˆ˜๊ฐ€ ๊ฐ™์€๊ฒฝ์šฐ,dfs(3,2)์ผ ๊ฒฝ์šฐ ์…‹์งธ์ž๋ฆฌ์ˆ˜๊ฐ€ num[2]์ผ๋•Œ์˜ ์ˆ˜์—ด๋“ค์„ ๋ฆฌํ„ดํ•ด์ฃผ๋Š” ํ•จ์ˆ˜

for (auto k : v) {
cout << k << " "; //๋ฒกํ„ฐ์— ์žˆ๋Š” ์ˆ˜์—ด์„ ์ถœ๋ ฅ
}
cout << "\n";
}
for (int j = 0; j < num_size; j++) { //์กฐํ•ฉ์ด ์•„๋‹ˆ๋ผ ์ˆ˜์—ด์ด๋ฏ€๋กœ ์ธ๋ฑ์Šค0๋ถ€ํ„ฐ ํƒ์ƒ‰์‹œ์ž‘
if (!visited[j]) { //num[j]๋ฅผ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด
visited[j] = true; //๋ฐฉ๋ฌธ ํ‘œ์‹œ๋ฅผ ํ•˜์—ฌ์ฃผ๊ณ 
v.push_back(num[j]); //๋ฒกํ„ฐ์— ๊ทธ ์ˆ˜๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.
dfs(cnt + 1, j); //์นด์šดํŠธ๋ฅผ ์˜ฌ๋ ค์ฃผ๊ณ  j๋กœ์ด๋™ํ•ด ๋‹ค์‹œ ํƒ์ƒ‰์ง„ํ–‰
v.pop_back(); //ํƒ์ƒ‰์ด ๋๋‚ฌ๋‹ค๋ฉด ๋ฒกํ„ฐ๋์—์„œ ์ˆ˜ ํ•˜๋‚˜๋ฅผ ๋นผ์ค€๋‹ค.
visited[j] = false; //๋‹ค๋ฅธ ๊ฒฝ์šฐ๋ฅผ์œ„ํ•ด j๋ฅผ ๋ฐฉ๋ฌธ์•ˆํ–ˆ๋‹ค๊ณ  ๋ฐ”๊ฟ”์ค€๋‹ค.
}
}
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> num_size >> picked_size;
for (int i = 0; i < num_size; i++) {
cin >> num[i];
}
sort(num, num + num_size); //์ž…๋ ฅ๋ฐ›์€ ์ˆ˜๋Š” ๋’ค์ฃฝ๋ฐ•์ฃฝ์ด๋ฏ€๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ์„ ์‹œ์ผœ์ค€๋‹ค.
dfs(0, 0);
}
Loading

0 comments on commit 67ffa0d

Please sign in to comment.