전체 글(334)
-
[BOJ] 1541번 : 잃어버린 괄호
1. problem : https://www.acmicpc.net/problem/1541 2. solution 1 :#include using namespace std;vector syms;vector nums;int main(void) { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; char current_sym = '+'; string num = ""; for (int i = 0; i 이 방법은 그리디를 이용한 풀이다. -를 보는순간 뒤에 있는 부호를 -로 바꾸는 과정이 포함된다. 전반적으로 코드가 더럽다. 다음번에는 이러한 코드를 작성하지말고, 아래와 같은 코드를 작성하자. 3. solution 2 :#include using nam..
2024.09.07 -
[BOJ] 2457번 : 공주님의 정원
1. problem : https://www.acmicpc.net/problem/2457 2. solution1 :#include using namespace std;#define X first#define Y second int n;pair flowers[100005];int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i > a >> b >> c >> d; if (b.length() == 1) b = "0" + b; if (d.length() == 1) d = "0" + d; flowers[i] = { stoi(a + b),stoi(c + d) }; } int ans = 0; int t = 301; ..
2024.09.07 -
[BOJ] 11399번 : ATM
1. problem : https://www.acmicpc.net/problem/11399 2. solution 1 :#include using namespace std;int n; int p[1005]; int d[1005];int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i > p[i]; sort(p + 1, p + n + 1); int ans = 0; for (int i = 1; i 누적합이 계속 더해지는 문제이다 보니, 최솟값부터 처리하는 게 맞다는 생각이 들었다. 따라서, greedy 전략이 필요하다. 이 과정에서 정답인 32가 안 나오고, 13이 나왔다. 디버깅을 해보니, 누적합을 더해야 하..
2024.09.07 -
[BOJ] 12865번 : 평범한 배낭
1. problem : https://www.acmicpc.net/problem/12865 2. solution 1 :#include using namespace std;int n, k; int w[100005], v[100005];int d[100005]; // 무게에따른 최대 value값 저장 int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i > w[i] >> v[i]; for (int i = 1; i = w[i]; m--) { d[m] = max(d[m], d[m - w[i]] + v[i]); } } cout 1. 무게에 따른 최대 value값을 저장하는 table을 정의한다.2. ..
2024.09.06 -
[BOJ] 1026번 : 보물
1. problem : https://www.acmicpc.net/problem/1026 2. solution 1 :#include using namespace std;int n; int a[55];int b[55]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > a[i]; for (int i = 0; i > b[i]; sort(a, a + n); sort(b, b + n, [](int& x, int& y) { return x > y; }); int ans = 0; for (int i = 0; i greedy 하게 들어갔다. a라는 수열을 오름차순으로, b라는 수열은 내림차순으로 정렬한 뒤,..
2024.09.06 -
[BOJ] 2217번 : 로프
1. problem : https://www.acmicpc.net/problem/2217 2. solution 1 :#include using namespace std;int n;int weights[100005]; int d[100005];int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > weights[i]; sort(weights, weights + n); for (int i = 0; i weights를 sort 해서 오름차순으로 정렬한 다음, 범위를 하나씩 좁혀가면서 무게의 분산을 고려해 최대 무게를 구했다. greedy 알고리즘을 이용했다.
2024.09.06