목록생활 (730)
No Rules Rules
카드 정렬하기 https://www.acmicpc.net/problem/1715 1715번: 카드 정렬하기 정렬된 두 묶음의 숫자 카드가 있다고 하자. 각 묶음의 카드의 수를 A, B라 하면 보통 두 묶음을 합쳐서 하나로 만드는 데에는 A+B 번의 비교를 해야 한다. 이를테면, 20장의 숫자 카드 묶음과 30장 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include using namespace std; int main(){ ios::sync_with_stdio(false), cin.tie(NULL); register int N, ans = 0; priority_queue q; cin >> N; for(regis..
예산 https://www.acmicpc.net/problem/2512 2512번: 예산 첫째 줄에는 지방의 수를 의미하는 정수 N이 주어진다. N은 3 이상 10,000 이하이다. 다음 줄에는 각 지방의 예산요청을 표현하는 N개의 정수가 빈칸을 사이에 두고 주어진다. 이 값들은 모두 1 이상 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include using namespace std; int main(){ ios::sync_with_stdio(false), cin.tie(NULL); register int N, M, arr[10000], sum, ans; cin >> N; for(register int n = 0; n < N;..
부등호 https://www.acmicpc.net/problem/2529 2529번: 부등호 두 종류의 부등호 기호 ‘’가 k개 나열된 순서열 A가 있다. 우리는 이 부등호 기호 앞뒤에 서로 다른 한 자릿수 숫자를 넣어서 모든 부등호 관계를 만족시키려고 한다. 예를 들어, 제시 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include using namespace std; int N; char sign[10]; bool visit[10]; set ans; void dfs(register int v, register int cnt, string str){ if(cnt == N){ ans.insert(str); ret..
로프 https://www.acmicpc.net/problem/2217 2217번: 로프 N(1 ≤ N ≤ 100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include using namespace std; int main(){ ios::sync_with_stdio(false), cin.tie(NULL); register int N, ans = 0, cnt = 0; priority_queue q; cin >> N; for(register int ..
영역 구하기 https://www.acmicpc.net/problem/2583 2583번: 영역 구하기 첫째 줄에 M과 N, 그리고 K가 빈칸을 사이에 두고 차례로 주어진다. M, N, K는 모두 100 이하의 자연수이다. 둘째 줄부터 K개의 줄에는 한 줄에 하나씩 직사각형의 왼쪽 아래 꼭짓점의 x, y좌표값과 오 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #include #include using namespace std; int M, N, K, dx[4], dy[4], arr[101][101]; bool visit[101][101]; vector ans; void bfs(register int ..
치즈 https://www.acmicpc.net/problem/2636 2636번: 치즈 아래 과 같이 정사각형 칸들로 이루어진 사각형 모양의 판이 있고, 그 위에 얇은 치즈(회색으로 표시된 부분)가 놓여 있다. 판의 가장자리(에서 네모 칸에 X친 부분)에는 치즈가 놓 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #include using namespace std; int R, C, dx[4], dy[4], arr[100][100]; bool visit[100][100]; int get_cheese_count(){ register int count = 0; for(register int r = 0, ..
환상의 짝꿍 https://www.acmicpc.net/problem/15711 15711번: 환상의 짝꿍 환상의 나라 디디랜드에서는 인연의 증표로 끈을 하나씩 가지고 있다. 그들은 지극히 평범한 방법으로 이 끈을 이용하여 어떤 두 사람이 환상의 짝꿍인지 판단하는데, 두 사람의 끈을 서로 이 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #define MAX_VALUE 2000000 using namespace std; int main(){ ios::sync_with_stdio(false), cin.tie(NULL); bool arr[MAX_VALUE + 5]{false}; arr[0] = arr[1]..
골드바흐의 추측 https://www.acmicpc.net/problem/6588 6588번: 골드바흐의 추측 각 테스트 케이스에 대해서, n = a + b 형태로 출력한다. 이때, a와 b는 홀수 소수이다. 숫자와 연산자는 공백 하나로 구분되어져 있다. 만약, n을 만들 수 있는 방법이 여러 가지라면, b-a가 가장 큰 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include #include #define MAX_VALUE 1000000 using namespace std; bool arr[MAX_VALUE]; int main(){ ios::sync_with_stdio(false), cin.tie(NULL); memset(ar..
가로수 https://www.acmicpc.net/problem/2485 2485번: 가로수 첫째 줄에는 이미 심어져 있는 가로수의 수를 나타내는 하나의 정수 N이 주어진다(3 ≤ N ≤ 100,000). 둘째 줄부터 N개의 줄에는 각 줄마다 심어져 있는 가로수의 위치가 양의 정수로 주어지며, 가 www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include using namespace std; int gcd(register int a, register int b){ return a % b ? gcd(b, a % b) : b; } int main(){ ios::sync_with_stdio(false), cin.tie(NULL); register in..
좋은수열 https://www.acmicpc.net/problem/2661 2661번: 좋은수열 첫 번째 줄에 1, 2, 3으로만 이루어져 있는 길이가 N인 좋은 수열들 중에서 가장 작은 수를 나타내는 수열만 출력한다. 수열을 이루는 1, 2, 3들 사이에는 빈칸을 두지 않는다. www.acmicpc.net // woohyeon.kim // kim519620.tistory.com #include #include using namespace std; int N; void solution(string str){ register int i = 0; while(++i N; solution(""); return 0; } // *&)*@* 문자열에 "1"을 추가하고 성공한다면 다시 "1"부터 추가하는 백트래킹 방식..