[백준] 17087: 숨바꼭질 6
2020. 12. 29. 05:47
Problem set
17087번: 숨바꼭질 6 수빈이는 동생 N명과 숨바꼭질을 하고 있다. 수빈이는 현재 점 S에 있고, 동생은 A1, A2, ..., AN에 있다. 수빈이는 걸어서 이동을 할 수 있다. 수빈이의 위치가 X일때 걷는다면 1초 후에 X+D나 X-D로 이 www.acmicpc.net #include #include using namespace std; int gcd(int x, int y) { if (y == 0) return x; else return gcd(y, x%y); } int main() { int n, s; cin >> n >> s; vector a(n); for (int i=0; i> x; int diff = x-s; if (diff < 0) diff = -diff; a[i] = diff; } i..
[백준] 16194: 카드 구매하기 2
2020. 12. 29. 05:45
Problem set
16194번: 카드 구매하기 2 첫째 줄에 민규가 구매하려고 하는 카드의 개수 N이 주어진다. (1 ≤ N ≤ 1,000) 둘째 줄에는 Pi가 P1부터 PN까지 순서대로 주어진다. (1 ≤ Pi ≤ 10,000) www.acmicpc.net #include #include using namespace std; int main() { int n; cin >> n; vector a(n+1); for (int i=1; i> a[i]; } vector d(n+1,-1); d[0] = 0; for (int i=1; i
[백준] 11727: 2×n 타일링 2
2020. 12. 29. 05:43
Problem set
11727번: 2×n 타일링 2 2×n 직사각형을 1×2, 2×1과 2×2 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×17 직사각형을 채운 한가지 예이다. www.acmicpc.net #include using namespace std; int d[1001]; void cal(int n) { d[0] = 1; d[1] = 1; d[2] = 3; for (int i = 3; i int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; cal(n); cout
[백준] 11726: 2×n 타일링
2020. 12. 29. 05:42
Problem set
11726번: 2×n 타일링 2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법의 예이다. www.acmicpc.net #include using namespace std; int d[1001]; void cal(int n) { d[0] = 1; d[1] = 1; for (int i = 2; i int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; cal(n); cout
[백준] 11052: 카드 구매하기
2020. 12. 29. 05:40
Problem set
11052번: 카드 구매하기 첫째 줄에 민규가 구매하려고 하는 카드의 개수 N이 주어진다. (1 ≤ N ≤ 1,000) 둘째 줄에는 Pi가 P1부터 PN까지 순서대로 주어진다. (1 ≤ Pi ≤ 10,000) www.acmicpc.net #include using namespace std; auto main()->int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; int* P = new int[(n + 1)](); int* d = new int[(n + 1)](); for (int i = 1; i > P[i]; } for (int i = 1; i
[백준] 10872: 팩토리얼
2020. 12. 29. 05:39
Problem set
10872번: 팩토리얼 0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오. www.acmicpc.net #include #include using namespace std; unsigned int facto(int n) { if (n == 1 || n == 0) { return 1; } return n * facto(n - 1); } auto main()->int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N; cin >> N; cout
[백준] 10870: 피보나치 수 5
2020. 12. 29. 05:37
Problem set
10870번: 피보나치 수 5 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가 www.acmicpc.net #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); function fib = [&fib](const int n){ if(n ==0){return 0;} return n > num; cout
[백준] 10866: 덱
2020. 12. 29. 05:36
Problem set
10866번: 덱 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net #include #include #include int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; deque dq; while (t--) { string cmd; cin >> cmd; if (cmd == "push_front") { int n; cin >> n; dq.push_fro..