본문 바로가기

백준

(497)
[백준 1377번] 버블 소트 (C++) 문제링크 : https://www.acmicpc.net/problem/1377 1377번: 버블 소트 첫째 줄에 N이 주어진다. N은 500,000보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 A[1]부터 A[N]까지 하나씩 주어진다. A에 들어있는 수는 1,000,000보다 작거나 같은 자연수 또는 0이다. www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; int N; vectorv; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; v.resize(N); for(int ..
[백준 2580번] 스도쿠 (C++) 문제링크 : https://www.acmicpc.net/problem/2580 2580번: 스도쿠 스도쿠는 18세기 스위스 수학자가 만든 '라틴 사각형'이랑 퍼즐에서 유래한 것으로 현재 많은 인기를 누리고 있다. 이 게임은 아래 그림과 같이 가로, 세로 각각 9개씩 총 81개의 작은 칸으로 이루 www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; int arr[9][9]; vectorv; bool check(int y, int x, int n) { for(int i=0; i
[백준 2239번] 스도쿠 (C++) 문제링크 : https://www.acmicpc.net/problem/2239 2239번: 스도쿠 스도쿠는 매우 간단한 숫자 퍼즐이다. 9×9 크기의 보드가 있을 때, 각 행과 각 열, 그리고 9개의 3×3 크기의 보드에 1부터 9까지의 숫자가 중복 없이 나타나도록 보드를 채우면 된다. 예를 들어 다 www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; int arr[9][9]; bool row[9][9], col[9][9], square[9][9]; void func(int cnt) { int y = cnt/9; int x = cnt%9; if(cnt==8..
[백준 17404번] RGB거리 2 (C++) 문제링크 : https://www.acmicpc.net/problem/17404 17404번: RGB거리 2 첫째 줄에 집의 수 N(2 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 각 집을 빨강, 초록, 파랑으로 칠하는 비용이 1번 집부터 한 줄에 하나씩 주어진다. 집을 칠하는 비용은 1,000보다 작거나 www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; int N, result = MAX; int arr[1001][3]; int dp[1001][3]; int main() { ios_base::sync_with_stdio(false); ..
[백준 1647번] 도시 분할 계획 (C++) 문제링크 : https://www.acmicpc.net/problem/1647 1647번: 도시 분할 계획 첫째 줄에 집의 개수 N, 길의 개수 M이 주어진다. N은 2이상 100,000이하인 정수이고, M은 1이상 1,000,000이하인 정수이다. 그 다음 줄부터 M줄에 걸쳐 길의 정보가 A B C 세 개의 정수로 주어지는데 A번 www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; struct p { int u, v, weight; bool operator> N >> M; for(int i=0; i> a >> b >> c; v.push_back({a, b..
[백준 14002번] 가장 긴 증가하는 부분 수열 4 (C++) 문제링크 : https://www.acmicpc.net/problem/14002 14002번: 가장 긴 증가하는 부분 수열 4 수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {10, 20, 10, 30, 20, 50} 이 www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; int arr[1001]; int dp[1001]; int len = 0; vectorv; int main() { ios_base:..
[백준 1254번] 팰린드롬 만들기 (C++) 문제링크 : https://www.acmicpc.net/problem/1254 1254번: 팰린드롬 만들기 동호와 규완이는 212호에서 문자열에 대해 공부하고 있다. 규완이는 팰린드롬을 엄청나게 좋아한다. 팰린드롬이란 앞에서부터 읽으나 뒤에서부터 읽으나 같게 읽히는 문자열을 말한다. 동호는 www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; bool check(string tmp) //펠린드롬인지 아닌지 확인 { for(int i=0; i> s; for(int i=0; i
[백준 1351번] 무한 수열 (C++) 문제링크 : https://www.acmicpc.net/problem/1351 1351번: 무한 수열 첫째 줄에 3개의 정수 N, P, Q가 주어진다. www.acmicpc.net #include using namespace std; typedef long long ll; typedef pair pii; const int MAX = 987654321; ll N, P, Q; map m; //시간초과 방지 ll func(ll n) { if(n==0) return 1; if(m[n]) return m[n]; //map에 값이 있으면 바로 return (중복방지) return m[n] = func(n/P) + func(n/Q); } int main() { ios_base::sync_with_stdio(0); c..