Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3-YIM2UL2ET #9

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion YIM2UL2ET/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
|:----:|:---------:|:----:|:-----:|:----:|
| 1μ°¨μ‹œ | 2023.10.27 | 그리디 | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) |
| 1μ°¨μ‹œ | 2024.02.12 | 그리디 | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) |
| 2μ°¨μ‹œ | 2024.02.15 | 그리디 | [BOJ 1263](https://www.acmicpc.net/problem/1263) | [BOJ 1449 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/7) |
| 3μ°¨μ‹œ | 2024.02.18 | 자료ꡬ쑰 | [BOJ 2504](https://www.acmicpc.net/problem/2504) | [BOJ 2504 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/7) |
---
41 changes: 41 additions & 0 deletions YIM2UL2ET/그리디/2μ°¨μ‹œ- BOJ 1263 .cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <algorithm>
#include <vector>

bool compare(std::vector <int> &vec1, std::vector <int> &vec2);

int main(void)
{
int n, result, end_time;
std::cin >> n;

std::vector <std::vector <int>> vec(n);
for (int i = 0; i < n; i++) {
int t, s;
std::cin >> t >> s;
vec[i].push_back(t);
vec[i].push_back(s);
}

std::sort(vec.begin(), vec.end(), compare);

result = vec[0][1] - vec[0][0], end_time = vec[0][1];
for (int i = 1; i < n; i++) {
if (end_time + vec[i][0] > vec[i][1]) {
result -= end_time + vec[i][0] - vec[i][1];
end_time = vec[i][1];
}
else end_time += vec[i][0];
}

if (result < 0) std::cout << "-1";
else std::cout << result;

return 0;
}

bool compare(std::vector <int> &vec1, std::vector <int> &vec2)
{
if (vec1[1] == vec2[1]) return vec1[0] < vec2[0];
else return vec1[1] < vec2[1];
}
41 changes: 41 additions & 0 deletions YIM2UL2ET/자료ꡬ쑰/3μ°¨μ‹œ - BOJ 2504.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <stack>
#include <vector>

int main(void)
{
bool is_Cstr = true;
std::string str;
std::stack <char> stk;
std::vector <int> vec;

std::cin >> str;

for (int i = 0; i < str.size(); i++) {
if (str[i] == '(' || str[i] == '[') {
stk.push(str[i]);
if (stk.size() > vec.size()) vec.push_back(0);
}
else if (!stk.empty() && ((str[i] == ')' && stk.top() == '(') || (str[i] == ']' && stk.top() == '['))){
int value;
if (stk.top() == '(') value = 2;
else value = 3;

if (stk.size() < vec.size()) {
vec[vec.size()-2] += vec.back() * value;
vec.pop_back();
}
else vec[vec.size()-1] += value;

stk.pop();
}
else {
is_Cstr = false;
break;
}
}

if (!is_Cstr || !stk.empty()) std::cout << 0;
else std::cout << vec[0];
return 0;
}