-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 10-yuyu0830
- Loading branch information
Showing
21 changed files
with
740 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.