Search

긴급 C++ 문법

카테고리
세부 카테고리
알고리즘
환경
작성 상태
앞선 내용
이어지는 내용
파일
int aaaaa(vector<vector<int>> &board) vector<vector<int>> board(3, vector<int>(3)); ios_base::sync_with_stdio(false); stirng S; getline(cin, S); #이분탐색 lower_bound(v.begin(), v.end(), 37);
Python
복사
#include <iostream>#include <vector>using namespace std; bool visited[9]; // 전역으로 선언하면 모두 false로 초기화 됨. vector<int> graph[9]; // 벡터 자체가 9개 void dfs(int x) { // 현재 노드 방문 처리 visited[x] = true; // 그와 연결된 방문하지 않은 노드를 발견할 때마다 재귀호출 for (int i = 0; i < graph[x].size(); i++) { int y = graph[x][i]; if (!visited[y]) dfs(y); } }
C++
복사
#include <iostream> #include <vector> #include <queue> using namespace std; bool visited[9]; vector<int> graph[9]; void bfs(int start) { queue<int> q; // 현재 노드 방문 처리 q.push(start); visited[start] = true; while(!q.empty()) { // 큐의 앞에서부터 원소를 하나씩 뽑아서 int x = q.front(); q.pop(); cout << x << ' '; // 그와 연결된 아직 방문하지 않은 노드들 모두 큐에 삽입 for(int i = 0; i < graph[x].size(); i++) { int y = graph[x][i]; if(!visited[y]) { q.push(y); visited[y] = true; } } } }
Python
복사
N의 범위가 500: 시간 복잡도가 O(N^3) 이하인 알고리즘을 설계
N의 범위가 2,000: 시간 복잡도가 O(N^2) 이하인 알고리즘을 설계
N의 범위가 100,000: 시간 복잡도가 O(NlogN) 이하인 알고리즘을 설계
N의 범위가 10,000,000: 시간 복잡도가 O(N) 이하인 알고리즘을 설계
N의 범위가 10,000,000,000: 시간 복잡도가 O(logN) 이하인 알고리즘을 설계