본문 바로가기

Algorithm/Implementation

(517)
(C++) - 백준(BOJ) 12852번:1로 만들기 2 답 문제링크 : https://www.acmicpc.net/problem/12852 단순 구현 문제였습니다.Top-Down 방식으로 풀었습니다. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include using namespace std;int d[1000001],ans[1000001];int go(int n) { int out; int m = 2000000000; int tmp; if (n == 1) { return 0; } if (d[n] > 0) { return d[n]; } tmp = go(n - 1) + 1; if (m > tmp) { out = n - 1; m = tmp; } if (..
(C++) - 백준(BOJ)코딩 7568번 : 덩치 답 www.acmicpc.net/problem/7568 7568번: 덩치 우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩 www.acmicpc.net 간단한 구현문제였습니다. 풀이방법 1. i보다 j번째 학생이 몸무게와 키 둘다 작을 경우(자기가 졌을 경우) rank[j[를 1씩증가해줍니다. 2. n까지 rank를 출력 Code #include using namespace std; int n; vector info; int main(){ cin >> n; for(int i = 0; i > x >> ..
(C++) - 백준(BOJ) 10814번 : 나이순 정렬 답 https://www.acmicpc.net/problem/10814 stable_sort()를 이용하면 나이가 같을 때 정렬의 순서가 유지되게 정렬할 수있습니다. 123456789101112131415161718192021222324252627//stable_sort()를 이용하면 나이가 같을 때 정렬의 순서가 유지되게 정렬할 수 있습니다.#include #include #include #include using namespace std;struct account { int age; string name;};bool cmp(const account &a, const account &b){ return a.age > n; vector a(n); for (int i = 0; i > a[i].age; cin ..
(C++) - 백준(BOJ) 11943번 : 파일 옮기기 www.acmicpc.net/problem/11943 11943번: 파일 옮기기 첫 번째 줄에는 첫 번째 바구니에 있는 사과와 오렌지의 수 A, B가 주어진다. (0 ≤ A, B ≤ 1,000) 두 번째 줄에는 두 번째 바구니에 있는 사과와 오렌지의 수 C, D가 주어진다. (0 ≤ C, D ≤ 1,000) www.acmicpc.net #include using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int ans = (b + c) < (a + d) ? (b + c) : (a + d); cout
(C++) - 백준(BOJ) 5717번 : 상근이의 친구들 #include using namespace std; int main() { int m, f; while (1) { cin >> m >> f; if (m == 0 && f == 0) break; cout
(C++) - 백준(BOJ) 10820번 : 문자열 분석 답 https://www.acmicpc.net/problem/10820 문자열 다뤄보는 문제입니다. 12345678910111213141516171819202122232425262728#include #include using namespace std;int ans[4],n;string k;int main() { while (1) { getline(cin, k); if (k == "") { break; } for (int i = 0; i
(C++) - 백준(BOJ) 9455번 : 박스 답 문제링크 : https://www.acmicpc.net/problem/9455 단순 구현 문제였습니다. 12345678910111213141516171819202122232425262728293031323334353637#include using namespace std;int M, N, a[101][101], t,ans,cnt;int main() { cin >> t; while (t--) { cin >> M >> N; for (int i = 1; i
(C++) - 백준(BOJ) 11966번 : 2의 제곱인가? 답 #include using namespace std; int main() { int n,sum=1; cin >> n; if (n == 1) { cout