본문 바로가기
  • Let's study

분류 전체보기120

[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.
[알고리즘] C++ 스택, 큐, 덱 스택 - 한 쪽 끝에서만 원소를 넣고 빼는 구조 - LIFO(Last In First Out): 나중에 들어온 것이 먼저 나감 - 헤더: #include - 선언: stack이름 기본 함수 - push(a): stack에 a 추가 - pop(): 제일 마지막에 추가된 원소 제거 - top(): 제일 마지막에 추가된 원소 반환 - empty(): stack이 비어있으면 true, 아니면 false 반환 - size(): stack에 들어있는 원소의 개수 반환 #include #include using namespace std; stacks; int main(){ s.push(1);//s={1} s.push(2);//s={1,2} s.push(3);//s={1,2,3} s.pop();//s={1,2} cout 2021. 9. 8.
[C++] 백준 6764번: Sounds fishy! 오타가 있는 문제입니다. 네 수가 모두 같을 때는 "Fish at Constant Depth"라고 출력해야 하고 적혀진 세 조건을 만족하지 못했을 때는 "No Fish"라고 출력해야 합니다.(No Fish에 . 을 빼야함) #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int arr[4]; int up = 0; int down = 0; int same = 0; for (int i = 0; i > arr[i]; } for (int i = 1; i arr[i - 1]) up++; else i.. 2021. 3. 13.