본문 바로가기
  • Let's study

분류 전체보기104

[알고리즘] Algorithm 헤더 - C++ min / max min(a,b): a와 b 중에 제일 작은 수를 반환 max(a,b): a와 b 중에 제일 큰 수를 반환 원래는 (a,b) 안에 2개의 값만 넣을 수 있지만 ({a,b,c,d}) 형식으로 사용하면 여러 값의 크기를 비교할 수 있다. #include #include using namespace std; int main(){ cout 2021. 9. 19.
[C++] 백준 2225번: 합분해 dp라는 건 금방 감이 왔고 N과 K가 만큼 더해야 하니까 2차원 배열을 써야겠다고 생각이 났다. dp 배열에서 행은 N, 열은 K를 저장한다고 볼 때 dp[3][3]을 구해보자. dp[1][1]=1, dp[1][2]=2, dp[1][3]=1; dp[2][1]=1, dp[2][2]=3, dp[2][3]=4; dp[3][1]=1, dp[3][2]=4, dp[3][3]=8; dp[2][2]=dp[1][1]+dp[1][2]이고 dp[3][3]=dp[2][1]+dp[2][2]+dp[2][3] 임을 볼 수 있다. #include #define MAX 1000000000 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0), c.. 2021. 9. 12.
[C++] 백준 2468번: 안전 영역 #include #include #include #include using namespace std; int arr[101][101]; bool visit[101][101]; int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 }; int n, height[101]; void dfs(int x, int y, int h) { visit[x][y] = true; for (int i = 0; i = 0 && nx = 0 && ny h) { dfs(nx, ny, h); } } } int main() { .. 2021. 9. 12.
[C++] 백준 20046번: Road Reconstruction #include #include #include #define MAX 1e9 using namespace std; int m, n; int dis[1001][1001]; int adj[1001][1001]; int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 }; int visit[1001][1001]; void dijkstra(int a, int b) { fill(&dis[0][0], &dis[1000][1001], MAX); priority_queue pq; if (adj[a][b] != -1) { dis[a][b] = adj[a][b]; pq.push({ -dis[a][b], {a,b} }); } while (!pq.empty()) { int c = -pq.top().f.. 2021. 9. 9.
[알고리즘] C++ Vector 사용법 vector란? 동적 배열로, 객체를 삽입하거나 제거할 때 자동으로 자신의 크기를 조정한다. - 헤더: #include vector 선언 방법 1. vector의 크기를 지정하지 않은 경우 vector이름; vectorv; 2. vector의 크기를 지정한 경우 vector이름(크기); vectorv(10); 3. vector의 크기를 지정하고 데이터를 특정 수로 초기화시키고 싶은 경우 vector이름(크기, 상수); vectorv(10,0); 4. vector에 특정 값을 넣어 선언하고 싶은 경우 vector이름={데이터1, 데이터2, ...}; vectorv = {1,3,5,2,7}; 5. 일반 배열처럼 사용하고 싶은 경우 vector이름[크기]; vectorv[1001]; 기본 함수 - resize.. 2021. 9. 9.
[알고리즘] C++ 기본 기본 구조 #include int main(){ return 0; } 입출력 입력: cin>>변수 출력: cout a >> b;//a와 b를 입력받음 std::cout a; cout 2021. 9. 9.