
[C++] Return Value Optimization(RVO)
2021. 1. 4. 01:56
C++
Return Value Optimization 이하 RVO 및, Named RVO(NRVO) 와 Copy-Elision 은 C++98 시절부터 도입됬으며, 런타임 퍼포먼스를 향샹시키는 기능을 한다. // Example.1 RVO #include using namespace std; struct Rain { // Note: All methods have side effects Rain() { cout int { Rain drop = RainDrop(); drop = RainDrop(); } // 출력결과 // c'tor // c'tor // move assignment // d'tor // d'tor // Returning Member struct RainWrapper{ Rain rain; }; Rain ..
[백준] 17413: 단어 뒤집기 2
2020. 12. 29. 05:48
Problem set
17413번: 단어 뒤집기 2 문자열 S가 주어졌을 때, 이 문자열에서 단어만 뒤집으려고 한다. 먼저, 문자열 S는 아래와과 같은 규칙을 지킨다. 알파벳 소문자('a'-'z'), 숫자('0'-'9'), 공백(' '), 특수 문자('')로만 이루어져 www.acmicpc.net #include #include #include using namespace std; void printstk(stack& stk) { while (!stk.empty()) { cout
[백준] 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