Algorithm(218)
-
[BOJ] 2170번 : 선 긋기
1. problem : https://www.acmicpc.net/problem/2170 2. solution 1 :#include using namespace std;#define X first #define Y secondint n; vector> v; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > x >> y; v.push_back({ x,y }); } sort(v.begin(), v.end()); int st = v[0].X, en = v[0].Y; int ans = 0; for (int i = 1; i en) { // v[i].X가 범위안에 있으면서 v[i].Y가 범위를 넓힐때 ..
2024.09.08 -
[BOJ] 1744번 : 수 묶기
1. problem : https://www.acmicpc.net/problem/1744 2. solution 1 :#include using namespace std;int n; vector vp; // 0이상의 정수 저장vector vn; // 음의 정수 저장int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i > x; if (x >= 0) vp.push_back(x); else vn.push_back(x); } sort(vp.begin(), vp.end()); sort(vn.begin(), vn.end(), [](int& a, int& b) { return a > b; }); int ans = 0..
2024.09.08 -
[BOJ] 11501번 : 주식
1. problem : https://www.acmicpc.net/problem/11501 2. solution 1 :#include using namespace std;int t; int stocks[1000005], maxPrices[1000005];int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i > stocks[i]; int maxPrice = INT_MIN; for (int i = n; i >= 1; i--) { maxPrice = max(maxPrice, stocks[i]); maxPrices[i] = maxPrice;..
2024.09.08 -
[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